Redirect to www using web.config redirect for ASP.NET Print
Written by Tom   

To redirect your ASP.NET website on IIS to www permanently follow the below example.

 

  • To redirect http://divorcedivisioncalculator.com/ to http://www.divorcedivisioncalculator.com/ permanantly.

 

  • Open your web.config file and add the below rule under <system.webServer>

 

 

<system.webServer>

.....

.....

.....

.....

<!-- code added -->

<rewrite>

<rules>

<rule name="non-www to www" enabled="true" stopProcessing="true">

<match url=".*" />

<conditions>

<add input="{HTTP_HOST}" pattern="^[^\.]+\.[^\.]+$" />

</conditions>

<action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" />

</rule>

</rules>

</rewrite>

<!-- code added -->

</system.webServer>

 

 

  • .com alternate method

 

 

<system.webServer>

.....

.....

.....

.....

<!-- code added -->

<rewrite>

<rules>

<rule name="Redirect to wwww" stopProcessing="true">

<match url="(.*)" />

<conditions>

<add input="{HTTP_HOST}" pattern="^divorcedivisioncalculator\.com$" />

</conditions>

<action type="Redirect" url="http://www.divorcedivisioncalculator.com/{R:1}" redirectType="Permanent" />

</rule>

</rules>

</rewrite>

<!-- code added -->

</system.webServer>

 

 

 

 

 

 

Althernatively you can set the www redirection from your cPanel of your web host. Contact your web host for help.