Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hi I know this question has been answered for other methods but in iis 7 how would one redirect all sites to www version. i.e to is there a method or would it be done in the same way as iis 6 where you created another site for and then redirected to www version, or is it best to use code to do this in global.asax or module. Thanks

share|improve this question

migrated from Jul 25 '10 at 4:18

This question came from our site for professional and enthusiast programmers.

Use the IIS URL Rewrite module. In particular, the exact rule you want is:

            <rule name="Canonical host name">
                <match url="^(.*)" />
                    <add input="{HTTP_HOST}" pattern="^www\.example\.com$" negate="true" />
                <action type="Redirect" url="{R:1}" />
share|improve this answer
thanks for that, but heres the situation. I have created a binding of and anything coming to brings up the site, anything coming to brings up default iis page. I have installed the rewrite module and can see it under the site where i have applied the rule and set httpredirect enabled="true" and even exactdestination="true" it does not seem to kick in for some reason – khan Jul 22 '10 at 20:01
I've noticed that the rule changes for the URL Rewrite module actually take some time to kick in. I believe this is due to the outgoing cache, though I haven't been able to the exact reason. – Franci Penov Jul 22 '10 at 20:53
is it correct to have the main binding set to the www version instead of the non-www version – khan Jul 22 '10 at 21:40
I would either not specify a host name in the binding, or if that's not an option, create a binding for both the www and the non-www versions of the domain. – Franci Penov Jul 22 '10 at 22:16
hi again appreciated but i just cannot get it working heres my setup pretty much. Bindings include both the www and none www bindings so the site appears on both, when the following rule is applied the site does not redirect rather it just times out. – khan Jul 23 '10 at 3:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.