繁体   English   中英

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

[英]How to redirect via web.config ASP.NET

我需要从 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 匹配“landing”字样,那么它也会重定向到 example.com/blog/info/landing。

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

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

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

<match url="^landing$" />

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM