Vinyl Warmth Vinyl Warmth - 17 days ago 6
ASP.NET (C#) Question

Too many redirects error after defining a redirect in Web.config

I have an ASP.NET MVC (5) application and need to redirect urls such as

<domain>/london
to
<domain>/locations/london


I've defined a redirect in Web.config in
system.Webserver


<rule name="london">
<match url="london" />
<action type="Redirect" url="locations/london" />
</rule>


When I run the site locally and browse to
localhost:1111/london
I get the following error


localhost redirected you too many times. ERR_TOO_MANY_REDIRECTS


What am I doing wrong?

I've spent some time looking online but can't find the answer...

Answer Source

your rule is basically saying if the URL contains London then redirect to locations/London. But locations/London contains the word London too so it will redirect again.

Try setting the rule to be

^london

(start with london)