IIS - HTTP Redirect all requests for one virtual directory to another
Posted
by
nekno
on Pro Webmasters
See other posts from Pro Webmasters
or by nekno
Published on 2012-11-20T19:29:19Z
Indexed on
2012/11/20
23:22 UTC
Read the original article
Hit count: 365
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>
© Pro Webmasters or respective owner