Knowledgebase
IIS web.config How to redirect domain.com to www.domain.com
Posted by PremiumReseller.com on 10 June 2011 04:05 PM
On Windows Server 2008 IIS 7.5

You can add rewrite rule in web.config file to redirect domain.com to www.domain.com

Replace domain.com with your domain


<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Canonical host name">
<match url="^(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.domain\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.domain.com/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
(164 vote(s))
This article was helpful
This article was not helpful