简体   繁体   中英

How to redirect via web.config ASP.NET

I need to redirect from example.com/landing to example.com/blog/info/landing. I wrote a rule in 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.

For example correct redirect: example.com/landing -> example.com/blog/info/landing

Wrong redirect example.com/somepage/1/landing -> example.com/blog/info/landing

Use a regex that matches /landing exactly:

<match url="^landing$" />

(IIS removes the leading / when doing regex matches)

The ^ and $ symbols are Regex Anchors that match the start and end of the string respectively.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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