【发布时间】:2023-01-20 15:00:53
【问题描述】:
我在 IIS 10(Windows 服务器)上运行 Wordpress 多站点。我有 3 个这样的网站。
<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 [重定向至] https://test.mydomain.com/subsite1
- 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 重写来做到这一点。
【问题讨论】:
标签: wordpress url-rewriting iis-10 url-rewrite-module