Wednesday, March 28, 2012

Non www to www Redirection with web.config in Asp.net

301 Redirection like non www to www for domain useful for SEO Purpose. I am going to describe how to done in asp.net with configuration in web.config . This is mostly develop how will be do except .htaccess file. On Shared hosting .htaccess file not supported. There fore we do setting in web.config.


Below code is for following scenario.
1. non www to www redirect
2. www.yourdomainname.com/default.aspx to www.yourdomainname.com

I am describing Step for do this Redirection non www to www in asp.net, There is following step for this:

Step 1. Add tag in System.webServer Tag
         
<rewrite>
      <rules>
        <rule name="Redirect to WWW" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^yourdomainname.com$" />
          </conditions>
          <action type="Redirect" url="http://www.yourdomainname.com/{R:0}" redirectType="Permanent" />
        </rule>
       
        <rule name="Default Document" stopProcessing="true">
          <match url="(.*?)/?default\.aspx$" />
          <action type="Redirect" url="{R:1}/" />
        </rule>
      </rules>
    </rewrite>

No comments:

Post a Comment

Reindex all table in Sql Database

 declare @tableName nvarchar(255) declare myCursor CURSOR FOR select TABLE_SCHEMA+'.'+TABLE_NAME from INFORMATION_SCHEMA.TABLES wher...