url重写时的重定向循环

时间:2015-06-22 20:40:01

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

我正在尝试避免为目标网页设置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>  

1 个答案:

答案 0 :(得分:0)

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

setLocation()

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

相关问题