IIS web.config重定向特定URL的规则,但不包括其他URL

时间:2017-02-28 15:45:25

标签: asp.net asp.net-mvc iis web-config

我想在web.config文件http://myurl.com/path/to/old中添加重定向规则 到http://myurl.com/path/to/new

但是http://myurl.com/fr/path/to/old

http://myurl.com/cn/path/to/old

应该保持不变。我如何通过匹配/规则实现这一目标?

1 个答案:

答案 0 :(得分:1)

将此添加到您的web.config:

<rewrite>
  <rules>
    <rule name="Redirect old to new" stopProcessing="true">
      <match url="^path/to/old" ignoreCase="false" />
      <conditions>
        <add input="{URL}" pattern="^fr/.*" ignoreCase="false" negate="true" />
        <add input="{URL}" pattern="^cn/.*" ignoreCase="false" negate="true" />
      </conditions>
      <action type="Rewrite" url="/path/to/new" />
    </rule>
  </rules>
</rewrite>