如何通过web.config ASP.NET重定向

问题描述 投票:0回答:1

我需要从example.com/landing重定向到example.com/blog/info/landing。我在web.config中写了一个规则

<rule name="Atlanta redirect" stopProcessing="true">
  <match url="landing" />
  <action type="Redirect" url="https://www.example.com/blog/info/landing" redirectType="Permanent" />
</rule>

但是如果url与“着陆”字词匹配,那么它也会重定向到example.com/blog/info/landing。

例如正确的重定向:example.com/landing-> example.com/blog/info/landing

错误的重定向example.com/somepage/1/着陆-> example.com/blog/info/着陆

c# asp.net redirect iis web-config
1个回答
0
投票

使用与/landing完全匹配的正则表达式:

<match url="^landing$" />

(IIS在进行正则表达式匹配时会删除前导/)>>

[^$符号是分别与字符串的开头和结尾匹配的正则表达式锚。

© www.soinside.com 2019 - 2024. All rights reserved.