How to set-up Wordpress Multi-sites on Azure using sub-directories

2.8k views Asked by At

A question on Wordpress Multisite running on Windows Azure using Sub-directories: does it work? how do you do it?.

I've installed Wordpress(4.2.2) from the Azure Gallery, updated the wp.config.php and web.config files to enable and install Multisites, but the result is a half working solution: Multi-sites is installed, and I can create and delete new sites, but the new sites have no css styling (404 errors) and I can't access their admin dashboards (404: The resource you are looking for has been removed, had its name changed, or is temporarily unavailable).

So, for example, the base website:

http://mywordpressmultisite.azurewebsites.net

works fine. But the multi-sites:

http://mywordpressmultisite.azurewebsites.net/site2/ http://mywordpressmultisite.azurewebsites.net/site3/

Display an unstyled css website, but I can't really do anything with them since I have no admin access; a routing error perhaps.

More Details

I've followed this how to article: https://azure.microsoft.com/en-gb/documentation/articles/web-sites-php-convert-wordpress-multisite/, to set-up Wordpress Multisite on Azure for sub-directories. I haven't followed on past the section entitled Add Custom Domains because I don't want to do that (yet, anyway).

My web.config file is:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <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-]+/)?wp-admin$" ignoreCase="false" />
                    <action type="Redirect" url="{R:1}wp-admin/" redirectType="Permanent" />
                </rule>
                <rule name="WordPress Rule 3" 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 4" 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 5" stopProcessing="true">
                    <match url="^([_0-9a-zA-Z-]+/)?([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" />
                    <action type="Rewrite" url="{R:2}" />
                </rule>
                <rule name="WordPress Rule 6" stopProcessing="true">
                    <match url="." ignoreCase="false" />
                    <action type="Rewrite" url="index.php" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

My wp-config.php is:

define( 'WP_ALLOW_MULTISITE', true );
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'mywordpressmultisite.azurewebsites.net');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

Things I've tried

  • Using both the Free and Shared hosting solutions.
  • Checking permalinks work on standard wordpress and the base No1 site (so mywordpressmultisite.azurewebsites.net/helloworld works).
  • Scrubbing down the database and starting the whole process again.
  • Changing file permissions to allow read, write and execute; just in case.

Debugging

I've configured the WebApp on Windows Azure to log everything possible but it's not spitting anything out. There's nothing in the php_error.log or other log files that I can find. I've configured wordpress wp-config.php as follows, but again nothing is being produced that I can find:

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', true);
@ini_set('display_errors', 0);

Where I am I'm flat out of ideas on how to get this work, and I'm beginning to wonder whether it actually does work on Azure for sub-directories? I have seen other references to this issue on the web but no solutions.

1

There are 1 answers

3
Anthony On BEST ANSWER

This stackoverflow question on IIS has the answer:

getting 404 error on admin panel for sub-directory multisite on a sub-domain in wordpress

It gives this XML for the web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <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="(^[_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*)" ignoreCase="false" />
                    <action type="Rewrite" url="{R:2}" />
                </rule>
                <rule name="WordPress Rule 6" stopProcessing="true">
                    <match url="^([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" />
                    <action type="Rewrite" url="{R:2}" />
                </rule>
                <rule name="WordPress Rule 7" stopProcessing="true">
                    <match url="." ignoreCase="false" />
                    <action type="Rewrite" url="index.php" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

I've uploaded this to Azure and it works. Theme's and dashboard are now accessible.

Not sure where the error is in the original web.config, which I would like to know as Wordpress seems to be providing the wrong web.config xml, but http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference may help work it out.

Edit:

It would seem these IIS web.config routing rewrite rules are based on the Apache .htaccess and Mod rewrite rules given here: https://codex.wordpress.org/Multisite_Network_Administration

The web.config which I found and used above, which does work, would appear to be derived from a .htaccess file targetting Wordpress versions of < 3.5.

Where as the original version provided by Wordpress, as part of the Mulisite install, is based on the .htaccess files targeting Wordpress 3.5+.

Web.config File Differences

Referencing rules from the working web.config in relation against those in the one which doesn't work:

  • Rule 1: Is identical.
  • Rule 2: This is an additional rule. Reviewing the Wordpress documentation this rule is no longer required for Wordpress versions 3.5+ (fresh installs) as ms-files.php is no longer used, so it can be removed.
  • [The following rules below are now out of sync!]
  • Rule 3: Identical to non working web.config's rule 2.
  • Rule 4: Identical to the orignal web.config's rule 3.
  • Rule 5. Almost the same, but the back reference url="{R:1}" is different. The working version uses url="{R:2}". I have seen this fix referenced elsewhere too.
  • Rule 6: This is similar to the Rule 5 in the original file, but the regular expression is shorter; However, it looks to me like these regular expressions may amount to the same thing. I'm sticking with the shorter version.
  • Rule 7: Identical to rule 6 in original web.config.

Leaving me with a reworked version which now looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="WordPress Rule 1 Identical" stopProcessing="true">
                    <match url="^index\.php$" ignoreCase="false" />
                    <action type="None" />
                </rule>

                <rule name="WordPress Rule 3 Identical" 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 Identical" 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 R2" stopProcessing="true">
                    <match url="^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*)" ignoreCase="false" />
                    <action type="Rewrite" url="{R:2}" />
                </rule>

                <rule name="WordPress Rule 6 Shorter" stopProcessing="true">
                    <match url="^([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" />
                    <action type="Rewrite" url="{R:2}" />
                </rule>


                <rule name="WordPress Rule 7 Identical" stopProcessing="true">
                    <match url="." ignoreCase="false" />
                    <action type="Rewrite" url="index.php" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>