Knowledgebase: IIS
How to redirect domain.com to www.domain.tld in web.config
Posted by Sean Syed on 13 February 2013 07:08 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

Option 1:

<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>

Option 2:

<system.webServer> <rewrite> <rules> <clear /> <rule name="WWW Rewrite" enabled="true"> <match url="(.*)" /> <conditions> <add input="{HTTP_HOST}" negate="true" pattern="^www\.([.a-zA-Z0-9]+)$" /> </conditions> <action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" /> </rule> </rules> </rewrite> <system.webServer>
(6 vote(s))
Helpful
Not helpful

Comments (0)
Post a new comment
 
 
Full Name:
Email:
Comments:
CAPTCHA Verification 
 
Please enter the text you see in the image into the textbox below (we use this to prevent automated submissions).