IIS 6 website redirect

Sometimes you have a website with many domains (org, com, net, etc.) and you want all of them to redirect to the main domain. This is very easy to accomplish with IIS (IIS 6, no modules required). IIS has a built in rewrite module that will let you redirect to a specific URL.

You could also have several URLs mapped to the same website in IIS, but this is not what we want, because we need that the secondary URLs actually redirect to the main one (meaning that domain.org/something would change to www.domain.com/something automatically).

You need to create a new website in IIS just for the redirects (meaning that all the secondary URLs can be mapped to this same website in IIS, so we can apply the redirect rule to all of them at the same time). You can use the same settings as the real website. The directory you choose doesn't matter, because it will be changed later.

To setup the redirection in IIS:

  • Go to the properties of the website entry where you want to setup the redirection.
  • Go to the Home Directory tab.
  • Select A redirection to a URL.
    • Type the URL you want to redirect to (something like http://www.example-new.com$S$Q - notice the parameters and the lack of dashes).
  • Check The exact URL entered above.
  • Check A permanent redirection for this resource if you want a permanent redirect (301) or leave it unchecked for a temporary redirect (302).

The parameters after the main URL tell IIS to redirect to the specific subdirectory and to use the query parameters that were requested. You can check in more detail what each parameter does in the Redirect reference for IIS 6.