Knowledgebase: IIS
How to redirect domain.com to www.domain.tld in web.config
Posted by on 29 November 2012 11:42 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>
(3 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).