title: web.config redirect non-www OR non-https to https://www using rules
body: <p>I need to redirect all non-www or non-https traffic to <code>https://www</code> using rule in web.config</p>
  
  <pre><code>http://domain.com --&gt; https://www.domain.com
  http://www.domain.com --&gt; https://www.domain.com
  https://domain.com --&gt; https://www.domain.com
  </code></pre>
  
  <p>I modified rules from <a href="https://stackoverflow.com/questions/8893284/web-config-redirect-all-traffic-to-www-my-using-rules-element">Web.config. Redirect all traffic to www.my... Using rules element.</a> but it fails to redirect <code>http://www.domain.com</code> to <code>https://www.domain.com</code>.</p>
  
  <pre><code>    &lt;rewrite&gt;
          &lt;rules&gt;
              &lt;clear /&gt;
              &lt;rule name="Redirect to www subdomain"&gt;
                  &lt;match url=".*" /&gt;
                  &lt;conditions logicalGrouping="MatchAll"&gt;
                      &lt;add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" negate="true" /&gt;
                      &lt;add input="{SERVER_PROTOCOL}" pattern="^(.*)(/.*)?$"/&gt;
                  &lt;/conditions&gt;
                  &lt;action type="Redirect" url="https://www.{HTTP_HOST}/{R:0}" redirectType="Permanent"/&gt;
              &lt;/rule&gt;
          &lt;/rules&gt;
      &lt;/rewrite&gt;
  </code></pre>