wordpress 将主站点重定向到子站点(IIS,Web.config)

nbnkbykc  于 2023-01-20  发布在  WordPress
关注(0)|答案(1)|浏览(193)

我在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.comhttps://test.mydomain.com/时,我想重定向到https://test.mydomain.com/subsite1
总而言之,我想这样工作。

我已经尝试过此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重写中完成它。

sshcrbum

sshcrbum1#

谢谢大家我在这里找到了答案https://stackoverflow.com/a/35759141

<rule name="Root Redirect" stopProcessing="true">
                    <match url="^$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Redirect" url="en/" redirectType="Permanent" />
                </rule>

相关问题