At DiscountASP.NET, we set up your web site to handle both www.YourHostedDomainName.com and YourHostedDomainName.com.  By having both hostnames (with or without www) bring up your web site, you don’t risk losing potential visitors.  This setup, however, is not favored by search engines.  According to many Search Engine Optimization experts, search engine bots will penalize you for duplicate content if you have multiple hostnames pointing to the same content.  SEO experts recommend the server returns a 301 permanent redirect to avoid getting penalized on your search engine ranking.

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

 

1 Response » to “How to use IIS7 URLRewrite Module to Enhance Search Engine Optimization”

  1. Anuj Rathi says:

    Hi Frank,
    Really very good article. I just want to confirm one thing.
    Some developers suggest to set “301 redirect” in global.asax beginRequest event.
    Can you please let me know which one is better & why?

Leave a Reply

iBlog by PageLines