IIS7 Redirects
May 19, 2010
posted by Rick Barber
IIS7 Redirects
There is often a need to redirect a domain name to another URL and there are a few ways to accomplish this. One of the cleanest and simplest ways make this happen in IIS7 is to use a HTTP Redirect. First you set up a site in IIS7 with the proper bindings to ensure only traffic that you want redirected will be served by this site and then configure a HTTP Redirect.
On a side note, if you are looking to redirect more than just a domain name and need granular control over the redirect I suggest that you look at the URL Rewrite Module, http://www.iis.net/download/URLRewrite. We have this module available on all of our IIS7 servers here at OrcsWeb.
Heading back to the discussion on HTTP Redirects, below is a screenshot of the HTTP Redirect screen that comes up when you choose that option in IIS.
What follows is a summary of the options on the screenshot. You should note that IIS7 has a comprehensive online help where you can get additional information.
If you check the first box under Redirect Behavior, it will force all requests to redirect to the exact destination entered in the top box. If you don’t check that box then requests will be relative to the destination entered. For example, if you were redirecting http://www.orcsweb.com and the incoming request was http://www.orcsweb.com/service, based on the redirect entered above, requests would be redirected to http://test.orcsweb.com/testing with the box checked. Without the box checked then requests would be redirected to http://test.orcsweb.com/testing/service.
If you check the second box under Redirect Behavior, it will redirect requests only to the subdirectory that you specified in the redirect destination. For example, with the second box checked in the screenshot above, redirects would only be served from the /testing directory.
The status code drop-down box allows you to set one of three options:
- Found (302) – This will cause the web browser to issue a new request to the redirect destination.
- Permanent(301) – This tells the web browser that the resource it requested has permanently changed to the redirect destination. This is what you will want to select if you need to preserve your search engine ranking and the URL is changing permanently.
- Temporary (307) – This prevents the browser from losing data when a HTTP POST request is issued and is a new option in IIS7.
The biggest reason I am writing this blog post is to mention the one caveat that I have run into when using a HTTP Redirect in IIS7. There appears to be some dependency on the physical path set in the advanced settings of the site. I know that sounds crazy but I have run into it a few times. Here is a scenario to explain this further.
Someone has more than one domain name pointing to a single website. Down the road they need one or more of those domain names to redirect somewhere else. The most convenient thing to do is set up a new site with the intention of using a HTTP Redirect once the site is setup. For consistency’s sake you point that other site to the same location as the original site. As soon as you setup the redirect it will set the redirect for every single site that is pointed to that same physical path in IIS. The way to get around it is to set each site to point to a different location.













