If you are hosting a web site in IIS and want to redirect it to an URL without much effort, “HTTP Redirect” is the feature you’re looking for.
It’s pretty straightforward. You give a target URL and set some options. I will be explaining what each option does through examples.
You will see 3 options in “Redirect Behavior” section:
- Redirect all requests to exact destination (instead of relative to destination)
- Only redirect requests to content in this directory (not subdirectories)
- Status code: Found (302), Permanent (301) or Temporary (307)
Scenarios
Target: http://www.bing.com/
localhost/mysite/ > http://www.bing.com/
localhost/mysite/test.aspx > http://www.bing.com/test.aspx
localhost/mysite/about > http://www.bing.com/about
localhost/mysite/about/details.aspx > http://www.bing.com/about/details.aspx
Target: http://www.bing.com/
localhost/mysite/ > http://www.bing.com/
localhost/mysite/test.aspx > http://www.bing.com/
localhost/mysite/about > http://www.bing.com/
localhost/mysite/about/details.aspx > http://www.bing.com/
Target: http://www.bing.com/
localhost/mysite/ > http://www.bing.com/
localhost/mysite/test.aspx > http://www.bing.com/
localhost/mysite/about > http://www.bing.com/
localhost/mysite/about/details.aspx > http://www.bing.com/
Target: http://www.bing.com/
localhost/mysite/ > http://www.bing.com/
localhost/mysite/test.aspx > http://www.bing.com/test.aspx
localhost/mysite/about > http://www.bing.com/about
localhost/mysite/about/details.aspx > http://www.bing.com/Default.aspx
Target: http://www.bing.com/sales
localhost/mysite/ > http://www.bing.com/sales/
localhost/mysite/test.aspx > http://www.bing.com/sales/test.aspx
localhost/mysite/about > http://www.bing.com/sales/about/
localhost/mysite/about/details.aspx > http://www.bing.com/sales/about/details.aspx
Target: http://www.bing.com/sales
localhost/mysite/ > http://www.bing.com/sales
localhost/mysite/test.aspx > http://www.bing.com/sales
localhost/mysite/about > http://www.bing.com/sales
localhost/mysite/about/details.aspx > http://www.bing.com/sales
Target: http://www.bing.com/sales
localhost/mysite/ > http://www.bing.com/sales
localhost/mysite/test.aspx > http://www.bing.com/sales
localhost/mysite/about > http://www.bing.com/sales
localhost/mysite/about/details.aspx > http://www.bing.com/sales
Target: http://www.bing.com/sales
localhost/mysite/ > http://www.bing.com/sales/
localhost/mysite/test.aspx > http://www.bing.com/sales/test.aspx
localhost/mysite/about > http://www.bing.com/sales/about
localhost/mysite/about/details.aspx > http://www.bing.com/sales/Default.aspx
Finally, status codes:
- Found (302): Tells the web client to issue a new request to the location. Also called “Moved Temporarily”. This is the default option.
- Permanent (301): Tells the web client that the location requested has permanently changed. If a client has link-editing capabilities, it should update all references to the Request URL. The response is cachable. If the 301 status code is received in response to a request of any type other than GET or HEAD, the client must ask the user before redirecting. Also called “Moved permanently”.
- Temporary (307): The request should be repeated with another URL; however, future requests should still use the original URL. In contrast to 302 status code, the request method is not allowed to be changed when reissuing the original request. For instance, a POST request should be repeated using another POST request. Prevents a Web browser from losing data when the browser issues an HTTP POST request. Also called “Temporary Redirect”
3 thoughts on “How does HTTP Redirection in IIS work?”