【问题标题】:Wordpress: Redirect main site to subsite (IIS, Web.config)Wordpress:将主站点重定向到子站点(IIS、Web.config)
【发布时间】: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。

总之,我想那样工作。

我试过这个 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


    【解决方案1】:

    谢谢大家。我在这里找到了答案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>
    

    【讨论】:

    • 人们倾向于关闭重复的问题,而不是发布新的答案,但您可以随意接受自己的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-10
    • 2014-02-20
    • 1970-01-01
    • 2023-04-08
    • 2015-05-30
    • 2022-01-13
    • 1970-01-01
    相关资源
    最近更新 更多