我在IIS 10(Windows服务器)上运行WordPress多站点。我有3个这样的站点。
- https://test.mydomain.com
- https://test.mydomain.com/wp-admin
- https://test.mydomain.com/subsite1
- https://test.mydomain.com/subsite2
<rewrite>
<rules>
<rule name="WordPress Rule 1" enabled="true" 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" enabled="true" stopProcessing="true">
<match url="." ignoreCase="false" />
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
它起作用了。
我并不真的需要主站点,所以我将主站点更改为2(https://test.mydomain.com/subsite1)
当用户访问网站https://test.mydomain.com或https://test.mydomain.com/时,我想重定向到https://test.mydomain.com/subsite1。
总而言之,我想这样工作。
- [重定向到]
- [重定向到]
- https://test.mydomain.com/wp-admin或wp-login或任何东西[它应该工作,因为它的。它不应该重定向到子网站。]
- https://test.mydomain.com/subsite1 [它应该按原样工作]
- https://test.mydomain.com/subsite1/wp-admin [它应该按原样工作]
- https://test.mydomain.com/subsite2/ [它应该按原样工作]
- https://test.mydomain.com/subsite2/wp-admin [它应该按原样工作]
我已经尝试过此IIS重写规则,但不起作用。
<rule name="Main To Subsite" enabled="true" stopProcessing="true">
<match url="^https:\/\/test.mydomain.com$" ignoreCase="false" />
<action type="Redirect" url="subsite1/" redirectType="Temporary" logRewrittenUrl="true" />
</rule>
<rule name="Main To Subsite /" enabled="true" stopProcessing="true">
<match url="^http:\/\/test.mydomain.com\/$" ignoreCase="false" />
<action type="Redirect" url="subsite1/" redirectType="Temporary" logRewrittenUrl="true" />
</rule>
我可能会使用一些正则表达式,如前瞻等。我不熟悉IIS重写。我已经阅读了,但仍然无法工作。任何帮助将不胜感激。
编辑:我发现了这个https://www.createit.com/blog/multisite-redirect-from-main-site/,但它是在functions.php中完成的。我认为我们应该能够从IIS重写中完成它。
1条答案
按热度按时间sshcrbum1#
谢谢大家我在这里找到了答案https://stackoverflow.com/a/35759141