Wednesday, December 12, 2012

Redirect www subdomain to root domain in ASP.NET

Let's say we want to perform permanent redirect from address to in our ASP.NET application for SEO purposes(URL canonization).

First of all, we need to download Rewrite module for IIS7:

Then you need to open IIS Manager and navigate to URL Rewrite section.

After proper configuration in IIS Manager you'll get section in your Web.config that can look like:
         <rule name ="CanonicalHostNameRule" stopProcessing="true">  
           <match url="(.*)" />  
             <add input ="{HTTP_HOST}" pattern="^www\." negate="false" />  
           <action type ="Redirect" url="{R:1}" />  

No comments:

Post a Comment