IIS web.config redirect rule for specific URL but not others

懵懂的女人 提交于 2021-01-29 03:01:01

问题


I want to add a redirect rule to the web.config file http://myurl.com/path/to/old to http://myurl.com/path/to/new

but http://myurl.com/fr/path/to/old

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

should stay the same. how can i achieve that with match/rule?


回答1:


Add this to your 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>


来源:https://stackoverflow.com/questions/42513071/iis-web-config-redirect-rule-for-specific-url-but-not-others

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!