Canonical domain redirects with IIS 5.0

with a few clicks of the mouse

[ List of other entries | oyoy.eu main page ]
 

This is a simple way to add a canonical redirect to your website (a 301-redirect from www to non-www or the other way around). It requires console access.

First of all, you need to set up separate entries for the www and non-www version of your website (usually using the host-header setting in IIS). Determine which version you want to redirect (for some help, try this tool to check the numbers on the canonical versons of a domain).

  1. Start -> Control Panel -> Administrative Tools -> Internet Information Services.
  2. Double-click "Web Sites" and then find the web site where the unpreferred domain is.
  3. Right-click on the unpreferred site and choose "Properties". Choose the "Directory" tab.
  4. Click the "A redirection to a URL" option.
  5. Enter the URL of the preferred domain to the right of "Redirect to:", add "$S$Q" to the end to redirect paths, files and querystrings (eg "http://www.domain.com$S$Q" - don't use the quotes).
  6. Select "The exact URL entered above" and "A permanent redirection for this resource".
  7. Use "OK" to save the changes.

Don't trust the settings - test them with the server header checker. The preferred domain should come normally, the other one should 301-redirect. Try some lower level pages and some parameters in the querystring to be certain that it's working everywhere. It must return code "301" (not 302).

If you do not have console access to IIS, you will have to include a script into all pages / scripts processed on the domain. An example of how to handle this can be found at http://www.jlh-design.com/2006/08/301-redirects-in-asp-on-iis-server/.