【问题标题】:IIS URL Rewrite negate conditions not workingIIS URL 重写否定条件不起作用
【发布时间】:2016-07-20 23:11:07
【问题描述】:

我想根据以下规则将一些页面从旧网站(oldsite.com)重定向到新网站(newsite.*):

  • 所有一级子节点(/sv、/no、/da 等)都应重定向到各自对应的节点,即 newsite.se、newsite.no、newsite.dk 等。
  • 所有其他子/后代也应重定向到新网站的根目录,除了 /page1 和 /page2 及其后代。

为此,我创建了以下规则(在本例中为 sv):

<rule name="Redirect /sv to .se" stopProcessing="true">
    <match url="^sv/?$" />
        <action type="Redirect" url="http://newsite.se" />
</rule>
<rule name="Redirect /sv/* except some pages" stopProcessing="true">
    <match url="^sv/.+" />
    <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_URI}" pattern="^sv/page1(.*)" negate="true" />
        <add input="{REQUEST_URI}" pattern="^sv/page2(.*)" negate="true" />
    </conditions>
    <action type="Redirect" url="http://newsite.se" />
</rule>

第一条规则可以正常工作,但第二条规则不行。问题是我的否定条件似乎不起作用。当我输入 oldsite.com/sv/page1 时,我仍然会被重定向到 newsite.se。也许我误解了否定条件的工作原理,但是当且仅当两个条件都为真(评估为假)时,第二条规则不应该执行操作,即 REQUEST_URI 匹配 /page1和 /page2?

【问题讨论】:

    标签: iis url-rewriting url-rewrite-module


    【解决方案1】:

    你非常了解这个概念。

    唯一的问题是{REQUEST_URI} 总是以/ 开头,并且url 永远不会匹配^sv/page1(.*) 这样的模式,最后你有一个全新的误报。

    因此,您需要在模式中包含前导斜杠。

    <add input="{REQUEST_URI}" pattern="^/sv/page1(.*)" negate="true" />
    <add input="{REQUEST_URI}" pattern="^/sv/page2(.*)" negate="true" />
    

    【讨论】:

      猜你喜欢
      • 2014-03-12
      • 2015-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-26
      • 1970-01-01
      • 1970-01-01
      • 2012-12-23
      相关资源
      最近更新 更多