setting up a 301 in iis

I recently encountered a scenario where a simple 301 redirect was setup in IIS which winded up breaking Google Analytics for AdWords tracking. What happened is that a 301 redirect was setup in order to combine www.website.com and website.com into one as www.website.com. This is a standard SEO tactic used to ensure that search engines only see one version of a website. This prevents duplicate content issues and focuses any PageRank received from inbound links to one site.

Here is the correct way to setup a 301 redirect in IIS:

  1. Open IIS.
  2. Right-click on your site (www.website.com) and select properties.
  3. Next to the IP Address field click ‘Advanced’ there should only be one IP with a host header value of www.website.com.
  4. Click OK.
  5. Create a new site (website.com).
  6. Right-click the new site (website.com) and select properties.
  7. Next to the IP Address field click ‘Advanced’ and add the same IP from www.website.com then set the host header value to website.com.
  8. Click OK.
  9. Click the ‘Home Directory’ tab.
  10. Click the ‘A redirection to a URL’ radio button.
  11. Insert the new URL, www.website.com in the ‘Redirect to:’ field.
  12. Check the box next to ‘The exact URL entered above’.
  13. Check the box next to ‘A permanent redirection for this resource’.
  14. Click OK.

Guess what – you just broke your website. Here’s how; If a backlink to your site uses a deep link, like website.com/folder/page.html and you set your redirect to www.website.com then anyone clicking that backlink will be sent directly to the root of your site (or worse) at www.website.com instead of the deep link page that you intended them to visit.

In order to properly execute a 301 redirect in IIS you must follow the ‘Redirect to:’ URL with $S$Q in order to pass the suffix of the URL to the redirected URL like this http://www.website.com$S$Q (note there is no / after the .com).

This change will allow http://website.com/folder/page.html to redirect to http://www.website.com/folder/page.html properly within IIS.

-Enjoy!

Check out this link if you need to setup 301 redirects in PHP / Apache.

Check out this link if you need more IIS 301 information.

UPDATE: You don’t need to add the $S$Q if you’re using IIS 7, it does this automatically. Consider this post to apply to IIS 6 and older.