Specify a canonical domain name for your site with IIS 7

Posted on July 13, 2010 by Frederik Vig in IIS

When setting up new sites in IIS you specify which host names map to your site. Usually this is at least two: www.example.com and example.com, sometimes even more. One great new addition to IIS 7 is the URL Rewriting extension. This allows you to setup a few rules for your URLs.

Let’s start by downloading and installing the URL Rewrite extension. The official IIS site has a download section with some very cool extension that I recommend you check out when you have the time. For now we only need the URL Rewrite extension. This will launch the Web Platform Installer, click Install and Accept. You should now see a new module in IIS.

URL Rewrite extension in IIS 7

To setup the rule we need for our canonical domain, just click the Add Rule(s) link and and under Search Engine Optimization (SEO) section choose Canonical domain name. Select a primary host name and you’re done!

Choose primary host name during Add rule with IIS URL Rewrite

What this does is redirect all traffic going to www.frederikvig.com to frederikvig.com, www.frederikvig.com/news to frederikvig.com/news etc, with a 301 (permanent redirect).

The reason this is important for SEO purposes is that search engines treat all URLs differently, so when you have two or more URLs all pointing to the same content your search ranking will suffer. Fortunately we have fixed this now with this rule, next time Google or some other search engine visits your site it will update it’s indexes, making all links point to the same domain name.

There are a lot of other great enhancements (Enforce lowercase URLs, User Friendly URLs etc) that I recommend checking out. Here are a few articles to get you started.

Related Posts: