Wednesday, February 23, 2011

Forcing canonical hostnames

Due to the restrictions of WCF services I was sent on a quest to find out how to manage allowing http://www.example.com and http://example.com. It wasn't as easy as I had hoped until I found this article.

I have seen all over the place that it is best practice to force canonical host names. This means example.com should be redirected to www.example.com. The problem with simple redirection is that it doesn't appear to redirect query strings so old links will break on you if you just use 301 redirects.

I asked around and found out you can accomplish redirection and keep query strings using the rewrite module for IIS. You can download it here.

The module simply sits in IIS's main features view. You can easily set it up to redirect all of your example.com pages to www.example.com using the following settings:

No comments:

Post a Comment