IIS Url Rewrite Wordpress

1

I have 2 servers on an internal LAN, a Windows 10 Pro PC running IIS (http://windows10-pc on the LAN), and then I have a Raspberry Pi running Apache 2 (http://raspberrypi on the LAN).

Both servers have Wordpress installed on them.

I did this since Wordpress takes up the root path on each web server instead of being able to have multiple instances on one web server. Even if I could do that, the MySQL databases use the wordpress database name, so I imagine it takes quite a bit of configuration to set up multiple Wordpress sites on one server.

I have URL Rewrite and ARR set up on the IIS machine so that if the external DDNS is pointing to a different host name it reroutes to the internal raspberry pi machine.

This works, except that URL links that I'm trying to access from the outside on each Wordpress install, are either going to http://localhost on the IIS machine, or http://raspberrypi on the Raspberry Pi. Only the homepages load from the outside, internally to the LAN they work fine.

Internally that works, and I need it to work like that inside the LAN, but from the outside it fails. Is it a Wordpress issue or an IIS/Apache issue, and how would I go about fixing it?

John Ernest

Posted 2019-07-30T05:03:55.930

Reputation: 143

1so I imagine it takes quite a bit of configuration to set up multiple Wordpress sites on one server. Not really, no. Just use separate domain names and database names for each site. It's relatively simple. – kicken – 2019-07-30T05:08:20.180

I just tried setting the site name to the DDNS host on each site, and it kicked me out of both Wordpress installs. Now I can't get in at all through the admin panel with the username/password I had in originally. I had to go into MySQL to set it back to localhost and then could get back into the website. – John Ernest – 2019-07-30T05:30:39.057

Ok so the issue is, let's say IIS server is setup on myhost.ddnsfree.com and the RPI server is setup on myhostpi.ddnsfree.com. It's making very long lookup times for URLs I guess because it's a DDNS I don't know, that's the thing. I don't know how to make that part do right. This is on a DDNS not on a static IP for a development server. – John Ernest – 2019-07-30T05:32:31.450

I don't use Wordpress much, but I setup a couple on IIS about 6 months ago and it was fairly straight forward. Setup two separate sites in IIS pointing to different folders. Unpack wordpress in each folder, then go through the install for each one using the appropriate URL. If you're trying to move an existing site, you may need to adjust the database to fix the site URL. – kicken – 2019-07-30T05:41:42.643

Answers

1

This needed to be in /var/www/html/wp-config.php on the RPI3, as well as /etc/wordpress/wp-config.php and /etc/wordpress/config-raspberrypi.php:

define('WP_DEBUG', false);

if (strpos($_SERVER['REMOTE_ADDR'], '192.168.1') !== false) { 
        define('WP_HOME', 'http://raspberrypi');
        define('WP_SITEURL', 'http://raspberrypi');
}
else if (isset($_SERVER['HTTP_X_ORIGINAL_HOST'])) {
        define('WP_HOME', 'http://'.$_SERVER['HTTP_X_ORIGINAL_HOST']);
        define('WP_SITEURL', 'http://'.$_SERVER['HTTP_X_ORIGINAL_HOST']);
}
else {
        define('WP_HOME', 'http://'.$_SERVER['SERVER_NAME']);
        define('WP_SITEURL', 'http://'.$_SERVER['SERVER_NAME']);
}

Also on the IIS server an HTTP_X_ORIGINAL_HOST server variable needed to be added. Any variables to be added must start with HTTP_X_ or they would not show up in PHP:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="ReverseProxyInboundRule1" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Rewrite" url="http://raspberrypi/{R:1}" logRewrittenUrl="true" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="outside-rpi-host.ddnsfree.com" />
                    </conditions>
                    <serverVariables>
                        <set name="HTTP_X_ORIGINAL_HOST" value="{HTTP_HOST}" />
                    </serverVariables>
                </rule>
                <rule name="wordpress" stopProcessing="true">
                    <match url=".*" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php" logRewrittenUrl="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

This should help anyone who has an IIS server on port 80 of their router, is hosting Wordpress on an RPI on a different IP on the LAN, and wants to use Url Rewrite to access the RPI from a different DDNS IP pointing to the same IP address. Enjoy, and may you have peace in Christ.

John Ernest

Posted 2019-07-30T05:03:55.930

Reputation: 143