I have a multi-site Drupal 7 install running on Azure that I would like to force all non-www traffic to the www address for all sites.

I have tried a number of examples from around the web but none of them seem to work.

Here is my current implementation, which looks like it should work, but does nothing.

<rule name="Redirect to www">
  <match url=".*" />
  <conditions logicalGrouping="MatchAny">
    <add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" negate="true" />
  <action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" redirectType="Permanent"/>

To clarify, yes, the above rule is nested inside <configuration> <system.webServer> <rewrite>

I've read about doing the redirect in settings.php but that seems kludgy to me and I'd rather do it right.

Any help would be greatly appreciated.

1 Answer 1


Some subtle differences between this and the rule above, but this officially works for my multi-site Drupal install on Azure IIS.

<rule name="WWW Rewrite" enabled="true">
          <match url="(.*)" />
                <add input="{HTTP_HOST}" negate="true" pattern="^www\.(.*)$" />
            <action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" />

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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