In this post, I am going to discuss a very simple technique for configuring your site to redirect YourHostedDomainName.com to www.YourHostedDomainName.com using the URLRewrite module. Note that this feature is only supported on the IIS 7.x platform.
1. Download and install IIS Manager. See our Knowledge Base for more information.
2. Connect to your site using the instructions listed in the above KB article.
3. Navigate to the URLRewrite section.
4. Click on “Add Rules” in the Action pane.
5. Configure the rules as below. I am using IIS7hosting.com for this example; make sure you replace iis7hosting.com with your own domain name.
6. Click “Apply” in the Actions pane.
7. IIS should now issue a 301 redirect for all requests going to iis7hosting.com and redirect them to www.iis7hosting.com.
8. Note that the URLRewrite rule is written to your web site’s web.config file. If you update your site in the future, your web.config file may be overwritten. I recommend that you add the URLRewrite rule to your local development web.config file.
Here’s the result of an HTTP header check to show that the rule is working properly:
Server Response: http://iis7hosting.com
HTTP Status Code: HTTP/1.1 301 Moved Permanently
Content-Type: text/html; charset=UTF-8
Location: http://www.iis7hosting.com/
Server: Microsoft-IIS/7.0
X-Powered-By: ASP.NET
Date: Tue, 09 Feb 2010 09:05:42 GMT
Connection: close
Content-Length: 150
Redirect Target: http://www.iis7hosting.com/
Frank Cheung
CTO