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

I'm using IIS 7 to host a web application. Currently, I have a rule in the web.config that re-directs all traffic to HTTPS, however it doesn't automatically redirect traffic to www which is important for some functionality. The web.config is shown below:

          <rule name="HTTP to HTTPS redirect" stopProcessing="true">
              <match url="(.*)" />
                  <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                  <add input="{URL}" pattern="seek\.svc$" ignoreCase="true" negate="true" />
              <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />

Can anyone tell me how to redirect all requests to www? Either using this route or using the IIS GUI.

I've found this: IIS 6 - Setting up 301 redirect for non-www to www for SEO

Which does the trick, but creating a duplicate site seems a little messy to me. Are there any other suggestions?


share|improve this question
What do you mean "redirect all to www" ? – Stephane Jan 17 '12 at 14:39
up vote 1 down vote accepted

Make a second ruleset before the existing one, without the stopProcessing flag, and add a condition that matches the www. before anything else and set the negate flag to true, like this:

<add input="{HTTP_HOST}" pattern="^www\.([.a-zA-Z0-9]+)$" negate="true" />

then add the www. to the url of your action like this:

<action type="Redirect" redirectType="Found" url="http://www.{HTTP_HOST}/{R:0}" appendQueryString="true" />
share|improve this answer
Thanks, works perfectly! – Paul Jan 17 '12 at 14:54

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.