Knowledgebase: Domains
How to redirect 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 to

Option 1:

<rule name="Canonical host name">
<match url="^(.*)" />
<add input="{HTTP_HOST}" pattern="^www\.domain\.com$" negate="true" />
<action type="Redirect" url="{R:1}" />

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))
Not helpful

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