IIS URL重写否定条件不起作用

Wil*_*iam 7 iis url-rewriting url-rewrite-module

我想根据以下规则将一些页面从旧网站(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>
Run Code Online (Sandbox Code Playgroud)

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

Kul*_*gin 10

你很了解这个概念.

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

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

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