Force non-www to www AND http to https

This method assumes that you already have a SSL Cert installed on your website.  This method also uses the IIS URL Rewrite Module which is installed on all of our servers.
 
You need to add the following block to your web.config between the <system.webServer> </system.webServer>  tags.
      <rewrite> 
       <rules> 
            <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>
       </rules> 
     </rewrite> 
 
Below is a simplified example web.config.
 <?xml version="1.0" encoding="UTF-8"?> 
 <configuration> 
   <system.webServer> 
     <rewrite> 
       <rules> 
            <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>
       </rules> 
     </rewrite> 
   </system.webServer> 
 </configuration> 
 

Add Feedback