【问题标题】:URL Rewrite redirect one page to another similar pageURL Rewrite 将一个页面重定向到另一个类似页面
【发布时间】:2021-04-06 15:24:30
【问题描述】:

如何使用 IIS 中的 URL Rewrite 或 web.config 将 2 个相似的 URL 重定向到 2 个不同的 URL?

我的 2 个旧网址是: http://example.com/used-2-3/ http://example.com/used-2-3-2/

我的 2 个新网址是

http://example.com/eq/ex?action=283 http://example.com/eq/ex?action=435

所以我的web.config重写规则是这样的,但它不起作用

<rule name="Used Conveyors Redirect" patternSyntax="ECMAScript" stopProcessing="true">
                    <match url="(.*)" negate="true" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{HTTP_HOST}{REQUEST_URI}" pattern="http://example.com/used-2-3/" />
                        <add input="{HTTP_HOST}{REQUEST_URI}" pattern="http://www.example.com/used-2-3/" />
                    </conditions>
                    <action type="Redirect" url="http://example.com/eq/ex?action=283" redirectType="Permanent" />
                </rule>
                <rule name="Used Power Vans" patternSyntax="ECMAScript" stopProcessing="true">
                    <match url="(.*)" negate="true" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{HTTP_HOST}{REQUEST_URI}" pattern="http://example.com/used-2-3-2/" />
                        <add input="{HTTP_HOST}{REQUEST_URI}" pattern="http://www.example.com/used-2-3-2/" />
                    </conditions>
                    <action type="Redirect" url="http://example.com/eq/ex?action=435" redirectType="Permanent" />
                </rule>


It is not working because both old links redirect to the first new URL.

【问题讨论】:

    标签: url redirect url-rewriting


    【解决方案1】:

    请注意,在您编写的规则中有条件logicalGrouping = "MatchAll",这意味着必须考虑ALL 匹配。我认为您应该使用“MatchAny”...

    无论如何,你为什么不使用这样一个简单的规则呢?

    <rule name="1stOLD" stopProcessing="true">
     <match url="^used-2-3\/$" />
     <action type"redirect" url="/eq/ex?action=283" />
    </rule>
    <rule name="2ndOLD" stopProcessing="true">
     <match url="^used-2-3-2\/$" />
     <action type"redirect" url="/eq/ex?action=435" />
    </rule>
    

    这 2 条规则捕获 http://www.example.comhttp://example.com 而不指定它。 “匹配网址”说:

    ^ : start with 
    used-2-3 : matches the characters used-2-3 literally 
    \/ : matches the character / literally 
    $ : the end of the string
    

    【讨论】:

      猜你喜欢
      • 2023-02-02
      • 2015-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-10
      • 1970-01-01
      • 1970-01-01
      • 2016-12-14
      相关资源
      最近更新 更多