title: IIS URLRewrite https non-www to https-www
body: <p>Having a tough time configuring rewrite rules. </p>
  
  <p>I basically want : </p>
  
  <ol>
  <li>Non www requests to be redirected to one with www </li>
  <li>Non https requests should be redirected to one with https</li>
  </ol>
  
  <p>Desired Redirects: </p>
  
  <pre><code>Requested Url                   Redirected To
  http://example.com              https://www.example.com/
  http://www.example.com          https://www.example.com/
  https://example.com             https://www.example.com/
  https://www.example.com         https://www.example.com/
  </code></pre>
  
  <p>Rewrite configuration 1: </p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;rules&gt;
      &lt;rule name="Redirect HTTP to HTTPS" stopProcessing="true"&gt;
          &lt;match url="(.*)" /&gt;
          &lt;conditions&gt;
              &lt;add input="{HTTPS}" pattern="^OFF$" /&gt;
          &lt;/conditions&gt;
          &lt;action type="Redirect" url="https://www.example.com/{R:0}" /&gt;
          &lt;!--redirect to https --&gt;
      &lt;/rule&gt;
      &lt;rule name="Add WWW prefix" stopProcessing="true"&gt;
          &lt;match url=".*" /&gt;
          &lt;conditions&gt;
              &lt;add input="{HTTP_HOST}" pattern="^example.com$" /&gt;
          &lt;/conditions&gt;
          &lt;action type="Redirect" url="https://www.example.com/" /&gt;
      &lt;/rule&gt;         
  &lt;/rules&gt;
  </code></pre>
  
  <p>Rewrite configuration 2: (from <a href="https://stackoverflow.com/questions/32490426/iis-redirect-non-www-to-www-and-http-to-https">IIS Redirect non-www to www AND http to https</a>). </p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;rules&gt;
      &lt;rule name="Force WWW and SSL" enabled="true" stopProcessing="true"&gt;
          &lt;match url="(.*)" /&gt;
          &lt;conditions logicalGrouping="MatchAny"&gt;
              &lt;add input="{HTTP_HOST}" pattern="^[^www]" /&gt;
              &lt;add input="{HTTPS}" pattern="off" /&gt;
          &lt;/conditions&gt;
          &lt;action type="Redirect" url="https://www.example.com/{R:1}" appendQueryString="true" redirectType="Permanent" /&gt;
      &lt;/rule&gt;
  &lt;/rules&gt;
  </code></pre>
  
  
  
  <p>The issue is mainly with <a href="https://example.com" rel="nofollow noreferrer">https://example.com</a> - it's not directing properly </p>