Vladyslav Ovcharenko
Vladyslav Ovcharenko

Reputation: 115

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

Upvotes: 2

Views: 640

Answers (1)

Dai
Dai

Reputation: 155015

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.

Upvotes: 2

Related Questions