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

[亡魂溺海] 提交于 2019-12-04 17:42:18
Anthony

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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!