IIS URL rewrite to canonical domain


It is considered good practice in view of search engines and site traffic analysis to always redirect from the "naked" domain like "mydomain.com" to the canonical domain "www.mydomain.com". This redirect should be done by the web server, before even getting to site code and content. To make IIS unconditionally redirect you need:
  • IIS version 7 and above
  • Microsoft IIS URL Rewrite 2 module installed (or supported by the hosting provider)
  • Code snippet below in your web.config file (at the root of your site)
Of course, you need to replace mydomain.com above with your domain name.
The IIS URL rewrite module is available here.

Back to List