IIS 8.5 redirect non www to www not working

iis-8.5windows-server-2012-r2

Here's the relevant bit of my Web.Config:

 <rule name="Force WWW and SSL" enabled="true" stopProcessing="true">
   <match url="(.*)" />
   <conditions logicalGrouping="MatchAny">
      <add input="{HTTP_HOST}" pattern="^[^www]" />
      <add input="{HTTPS}" pattern="off" />
   </conditions>
   <action type="Redirect" url="https://www.zzz.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
 </rule>

Here's the relevant bit of my Web.Config:

It will rewrite http to https but will not add the www as needed by my cms. I've tried several variants of this and it just seems that IIS 8.5 on Win2012R2 refuses to follow the www rule. Any ideas?

Best Answer

Give this a shot:

<rule name="Canonical Host Name (HTTPS)">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTPS}" pattern="(on)" ignoreCase="false" negate="true" />
        <add input="{HTTP_HOST}" pattern="^(?!www\.)(.+)$" />
    </conditions>
    <action type="Redirect" url="http://www.{C:0}/{R:1}" />
</rule>