【问题标题】:Redirection loop when url rewritingurl重写时的重定向循环
【发布时间】:2015-09-08 11:07:15
【问题描述】:

我试图避免我的着陆页有 2 个不同的网址,所以我想将没有指定文化 (www.example.com) 的着陆页重定向到 www.example.com/en-us

我想要实现的是以 example.com 结尾的链接重定向到 example.com/en-us

这是我在 web.config 中的规则:

    <rule name="Redirect to En Us" stopProcessing="true">
      <match url=".*" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="example.com$" />
      </conditions>
      <action type="Redirect" url="/en-us" redirectType="Permanent" />
    </rule>  

但即使网址不是以 example.com

结尾,它也只是停留在重定向循环中

更新:

这不会陷入循环,但也不会重定向(似乎正则表达式根本不匹配,但为什么?):

<rule name="Redirect to En Us" stopProcessing="true">
  <match url="example.com$" />
  <action type="Redirect" url="/en-us" redirectType="Permanent" />
</rule>  

【问题讨论】:

    标签: asp.net url-rewriting web-config


    【解决方案1】:

    好吧,我终于明白了。我只需要告诉如果 url(不包括主机名)为空然后重定向:

    <rule name="Redirect to En Us" stopProcessing="true">
      <match url="^$" />       
      <action type="Redirect" url="/en-us" redirectType="Permanent" />
    </rule>  
    

    您可能还需要查找尾部斜杠,但在我的情况下,因为我已经有一个删除尾部斜杠的规则,这不是问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多