We have a wordpress multi site, the main site has a URL similar to mainsite.com

Each of the sub sites have a URL such as subdomain1.mainsite.com, subdomain2.mainsite.com etc Each of the sub sites we would like to potentially hide behind a separate reverse proxy eg revprox1.com/rp1subsite shows subdomain1.mainsite.com, revprox2.com/rp2subsite shows subdomain2.mainsite.com etc

Doing the reverse proxy on IIS7 works using the code below and the site is displayed on the relevant reverse proxy URL, however all the hyper links on the page refer to the original URL and not the reverse proxy due to wordpress using absolute paths. We installed a plugin to force wordpress to enforce relative paths for all the links, at this point all the links worked, the reverse proxy folder was appended to the beginning of the link, however the CSS was broken as it was looking for the CSS at the root of the reverse proxy and was not appending the reverse proxy folder eg it was looking for the CSS at revprox1.com/css.css rather than revprox1.com/rp1subsite/css.css

I was wondering if anyone has ever tried to set Wordpress up like this before and what I should be looking at to combat this problem, as if the CSS was looking in the correct place it would work for us. We cant really be changing the database as we want to be able to allow our site administrators to setup new sites with minimal involvement from IT.

    <rule name="Reverse Proxy to Site 1" stopProcessing="true">
        <match url="^rp1subsite/(.*)" />
        <action type="Rewrite" url="http://subdomain1.mainsite.com/{R:1}" />
    <rule name="Reverse Proxy to Site 2" stopProcessing="true">
        <match url="^rp2subsite/(.*)" />
        <action type="Rewrite" url="http://subdomain2.mailsite.com/{R:1}" />
    <rule name="Add application prefix" preCondition="IsHTML">
        <match filterByTags="A" pattern="^/(.*)" />
            <add input="{URL}" pattern="^/(rp1subsite|rp2subsite)/.*" />
        <action type="Rewrite" value="/{C:1}/{R:1}" />
        <preCondition name="IsHTML">
            <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />

If you want wordpress to behave nice when asked to serve content from example.com you need to configure it to know that. This is done automatically at the install process for the domain on which wordpress is installed on but can also be controlled from wp-config.php by setting values to the WP_HOME and WP_SITEURL constants.

What you need to do is set the contants differently when a request comes from your proxy. You should have in your wp-config.php something like

if (request is comming from the proxy) {
  define('WP_HOME', 'http://www.revproxy.com'); 
  define('WP_SITEURL', 'http://www.revproxy.com');

This will solve problem with all the URLs which are generated by the wordpress APIs, but you will still need the code to convert links in the content to be "relative" or replace the domain based on the value of WP_HOME

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.