IIS - HTTP Redirect all requests for one virtual directory to another
- by nekno
How do I set up an HTTP Redirect rule to redirect all requests for a virtual directory to another virtual directory, when I don't know the hostname or complete URL, and cannot use the URL Rewrite module?
The following redirects should work:
http://host1/app/oldvdir -> http://host1/app/newvdir
http://host1/app/oldvdir/ -> http://host1/app/newvdir/
http://host1/app/oldvdir/login.aspx -> http://host1/app/newvdir/login.aspx
http://host2/app/oldvdir/login.aspx -> http://host2/app/newvdir/login.aspx
I would like to place the redirect rule in the app's root web.config. I have attempted the following rules, but the end result is simply that the redirected vdir gets duplicated on the end of the original vdir until reaching the max URL length, e.g.,
http://host/oldvdir/login.aspx -> http://host/oldvdir/newvdir/newvdir/newvdir/...
Rules in root web.config (I also have tried all sorts of combinations of settings with and without leading and trailing slashes, etc):
<location path="oldvdir">
<system.webServer>
<httpRedirect enabled="true" exactDestination="false" httpResponseStatus="Permanent">
<add wildcard="*/oldvdir/*" destination="/newvdir/"/>
</httpRedirect>
</system.webServer>
</location>
<location path="oldvdir/">
<system.webServer>
<httpRedirect enabled="true" exactDestination="false" destination="/newvdir" httpResponseStatus="Permanent"/>
</system.webServer>
</location>