Web developers wiki ASP.NET Sitecore Sharepoint Kentico by Evident Interactive

Using IIS redirects in IIS7

Modified: 2010/10/20 11:04 by k.schepens - Categorized as: IIS
Edit

How to use redirects in IIS 7

Edit

Goal

In case a website needs to be redirected to another site (eg. when switching from a www2 subdomain to a www domain), the easiest way to do this in IIS7, is setting up HTTP Redirects (Web-HTTP-Redirect module).

Edit

Installing Web-Http-Redirect

This module is shipped with IIS7, however default not installed. If it is not installed (check if there is a node called "HTTP Redirect" under the Features View in IIS7), it can be installed by using command prompt:

servermanagercmd -install Web-HTTP-Redirect

Image

(this might take a while)

Edit

Setting up the redirects

When redirecting to another web site on the same IIS machine, it is best to add a new site pointing to an empty folder. Enable redirects on this site.

To add redirecting to a website, click the newly created site (pointing to the empty folder). In Features view, click HTTP Redirect. In HTTP Redirect view, enter the full url of the website to redirect to. Example:

http://redirect.destination.url

For permanent redirection, set Status code to Permanent (301). This will also update search engine results.

There are a couple of things to keep in mind when using redirects.

Firstly, never create a redirect to a site that points to the same physical path (even though it's another site). This will create an endless loop since IIS will add the redirects in the web.config file.

Initially, the option "Redirect all requests to exact destination" is unchecked. This is fine unless you also want to include the querystring to the redirects. In order to enable redirecting querystrings, this option must be checked and the destination must be altered to:

http://redirect.destination.url$V$Q

$V will add the path $Q will add the querystring

Image

 © Evident Interactive BV