WordPress Networks - IIS Rewrite Rules on Azure App Service

Published on Tuesday, 13 September 2016

This is a bit of an extension to my previous post.

One of the last blogs I moved was a MU or a multi-user WordPress blog, which is now known as a Network. This turned out to be a bit more challenging than the single WP blogs. To setup a new instance, these instructions should mostly do the trick however, based on my testing you'll still need the rewrite rules below.

From this post and this post, I was able to assemble the following rewrite rules that have worked for my WPMU blog running on the Azure App Services (as of Sept. 13, 2016)! Don't miss the <httpRedirect enabled="false" ....> line at the bottom - that was very important. You'll also need those MU settings out of your wp-config.php file too.

web.config:

<system.webServer>
    <rewrite>
        <rules>
            <rule name="WordPress Rule 1" stopProcessing="true">
                <match url="^index\.php$" ignoreCase="false" />
                <action type="None" />
            </rule>
            <rule name="WordPress Rule 2" stopProcessing="true">
                <match url="^([_0-9a-zA-Z-]+/)?files/(.+)" ignoreCase="false" />
                <action type="Rewrite" url="wp-includes/ms-files.php?file={R:2}" appendQueryString="false" />
            </rule>
            <rule name="WordPress Rule 3" stopProcessing="true">
                <match url="^([_0-9a-zA-Z-]+/)?wp-admin$" ignoreCase="false" />
                <action type="Redirect" url="{R:1}wp-admin/" redirectType="Permanent" />
            </rule>
            <rule name="WordPress Rule 4" stopProcessing="true">
                <match url="^" ignoreCase="false" />
                <conditions logicalGrouping="MatchAny">
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" />
                </conditions>
                <action type="None" />
            </rule>
            <rule name="WordPress Rule 5" stopProcessing="true">
                <match url="^" ignoreCase="false" />
                <conditions logicalGrouping="MatchAny">
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" />
                    <add input="{URL}" pattern="([a-zA-Z0-9\./_-]+)\.axd" />
                </conditions>
                <action type="None" />
            </rule>
            <rule name="WordPress Rule 6" stopProcessing="true">
                <match url="^[_0-9a-zA-Z-]+/(wp-(content|admin|includes)?.*)" ignoreCase="false" />
                <action type="Rewrite" url="{R:1}" />
            </rule>
            <rule name="WordPress Rule 7" stopProcessing="true">
                <match url="." ignoreCase="false" />
                <action type="Rewrite" url="index.php" />
            </rule>
        </rules>
    </rewrite>
    <httpRedirect enabled="false" destination="http://www.examplesite.com" />
</system.webServer>

wp-config.php:

define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'www.examplesite.com');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);