13 August 2016 Sudhanshu Ranjan 532

Redirect URL non-www to www using web.config in MVC ASP.Net

Guys, this is most important part while you are hosting a domain on server because once you will host the application it will be open through like http://www.yourdomainname.com or http://yourdomain.com which is not good for SEO purpose and as well as Google search engine. In these scenarios Google understand that both are different URL’s.

Follow the step to resolve the issue.

Step 1: Open web.config file and under the <system.webserver> section you can add following code.

<rewrite>
  <rules>
    <rule name="Redirect non wwww to www HTTP" patternSyntax="ECMAScript" stopProcessing="true">
      <match url=".*"></match>
      <conditions>
        <add input="{HTTP_HOST}" pattern="^yourdomainname.com$"></add>
        <add input="{HTTPS}" pattern="off"></add>
      </conditions>
      <action type="Redirect" url="http://www.yourdomainname.com/{R:0}" redirectType="Permanent" appendQueryString="true"></action>
    </rule>
  </rules>
</rewrite>

 

Step 2:  Replace yourdomainname.com with your domain name.

You can share at :

About Author
Sudhanshu Kumar Ranjan | Lead Engineer at HCL Technologies | Expertise in Microsoft Technology | Author | Blogger | Programmer
Know More
Connect with him on Facebook | Google+ | LinkedIn | Twitter

Recommended Post

Leave a comment

About Dotnet Cube

It's my blog - Dotnet Cube, where you will learn and get solutions about programming, web designing and development. I started this website to share my knowledge and experience which might help someone.

You can get more details about me and my blog at About Us page.

Subscribe Newsletter

Subscribe to our monthly newsletter to get the latest industry news, Media Group updates and our current specials.

Follow On Us...

Home | About | Advertise | Copyrights | Privacy | Contact | Admin

Copyrights © 2015-2017 dotnetcube.com. All rights reserved