简体   繁体   English

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

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

I need to redirect from example.com/landing to example.com/blog/info/landing.我需要从 example.com/landing 重定向到 example.com/blog/info/landing。 I wrote a rule in web.config我在 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>

but if url matches "landing" word then it redirect to example.com/blog/info/landing too.但如果 url 匹配“landing”字样,那么它也会重定向到 example.com/blog/info/landing。

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

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

Use a regex that matches /landing exactly:使用与/landing完全匹配的正则表达式:

<match url="^landing$" />

(IIS removes the leading / when doing regex matches) (IIS 在进行正则表达式匹配时会删除前导/

The ^ and $ symbols are Regex Anchors that match the start and end of the string respectively. ^$符号是分别匹配字符串开头和结尾的正则表达式锚。

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

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