【问题标题】:Multiple web.config redirect rules多个 web.config 重定向规则
【发布时间】:2012-05-07 18:04:26
【问题描述】:

我正在尝试进行 301 重定向,因为我已经更改了域。使用 windows 服务器并在 web.config 中添加以下规则。

 <rule name="redirectDomain" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Redirect" url="http://replacement-cost.net/{R:1}" redirectType="Permanent" />
                    <conditions logicalGrouping="MatchAny">
                        <add input="{HTTP_HOST}" pattern="^(www.)?windshield-replacement-cost\.org$" />
                    </conditions>
              </rule>

只要新站点上的所有页面都具有相同的名称和文件结构,就可以正常工作...除了作为旧域根的页面之外。现在在http://replacement-cost.net/windshield-replacement-cost

是否可以编写另一个规则来仅重定向根目录?而让第二条规则重定向所有其他页面?可能是某种执行顺序?

基本上可以达到与此相同的结果

如果 ruleURLISROOT = true > 转到http://replacement-cost.net/windshield-replacement-cost

其他

使用上面的代码重定向

任何帮助将不胜感激。我花了很长时间才走到这一步!谢谢

【问题讨论】:

    标签: asp.net windows web-config http-status-code-301


    【解决方案1】:

    这是新规则,应在现有规则之前添加

    <rule name="redirect Root Domain" stopProcessing="true">
        <match url="^$" />
        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
            <add input="{HTTP_HOST}" pattern="^(www.)?windshield-replacement-cost\.org$" />
        </conditions>
        <action type="Redirect" url="http://replacement-cost.net/windshield-replacement-cost" />
    </rule>
    

    这是你现有的规则

    <rule name="redirectDomain" stopProcessing="true">
        <match url="(.*)" />
        <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
            <add input="{HTTP_HOST}" pattern="^(www.)?windshield-replacement-cost\.org$" />
        </conditions>
        <action type="Redirect" url="http://replacement-cost.net/{R:1}" redirectType="Permanent" />
    </rule>
    

    【讨论】:

    • 完美——先生,你是个传奇!
    猜你喜欢
    • 2019-08-02
    • 2015-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多