Mobile app version of vmapp.org
Login or Join
Looi9037786

: IIS - HTTP Redirect all requests for one virtual directory to another How do I set up an HTTP Redirect rule to redirect all requests for a virtual directory to another virtual directory, when

@Looi9037786

Posted in: #AspNet #Iis #Iis7 #Redirects

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:
host1/app/oldvdir -> host1/app/newvdir http://host1/app/oldvdir/ -> host1/app/newvdir/ http://host1/app/oldvdir/login.aspx -> host1/app/newvdir/login.aspx http://host2/app/oldvdir/login.aspx -> 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.,
host/oldvdir/login.aspx -> 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>

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Looi9037786

2 Comments

Sorted by latest first Latest Oldest Best

 

@Rambettina238

It's unfortunate that the MS documentation is so lacking on this subject. Fortunately, I was able to figure this out. I found the $S and $Q terms documented in the IIS6.0 documentation.

<configuration>
<location path="app/oldvdir">
<system.webServer>
<httpRedirect enabled="true" destination="/app/newvdir$S$Q" exactDestination="true"/>
</system.webServer>
</location>
</configuration>

10% popularity Vote Up Vote Down


 

@Angie530

Few things you can do.


Delete the virtual directory. Select the folder you want to redirect requests too, and add that as a virtual directory with the old name. So you delete OldVdir, and then create it again as OldVDIR but this time with the source as new vdir.
You can use .asp .aspx to do the redirect. In asp, you can do a response.redirect if you are lazy, or you can do a it properly like this:

gist.github.com/4153268

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme