Skip to main content
1 of 2

Configure web.config to redirect non-www requests to www for multi-site Drupal 7 Install

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.

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

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.