Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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>
share|improve this question
add comment

1 Answer

Few things you can do.

  1. 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.

  2. 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:

https://gist.github.com/4153268

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.