Need to get a site redirecting both to www and https
<p>Parts of other answers on Stack Overflow worked, other parts didn't, so I thought I would ask for the full solution including IIS settings re bindings.</p>
<p>I have a site (old ASP classic) that is being moved to IIS 8 (2012).</p>
<p>The site works when testing it from my hosts file.</p>
<p>At the moment I can only get it to redirect http to https not non www requests to <a href="http://www.example.com" rel="nofollow noreferrer">www.example.com</a> as well.</p>
<p>So I have 2 bindings in IIS (80/433) for <a href="http://www.example.com" rel="nofollow noreferrer">www.example.com</a>, I also tried it with another set without the www. e.g example.com but then I got errors such as the system is trying to process your request in such a way it won't return e.g following redirects around in a circle etc.</p>
<p>I am not so sure if that was about the 2 lots of bindings or the rules it was getting a bit messy then. So I need the whole approach from IIS binding setup and web.config rules (or is there a better way in IIS 8 to force all 80 traffic to port 443?)</p>
<p>I already have a number of ISAPI rules in my web.config file such as</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;rule name="Order" stopProcessing="false"&gt;
    &lt;match url="^applications/order/?$" /&gt;
    &lt;conditions logicalGrouping="MatchAll" trackAllCaptures="false" /&gt;
    &lt;action type="Rewrite" url="plugins/order.asp" /&gt;
&lt;/rule&gt;
&lt;rule name="Robots 1" stopProcessing="false"&gt;
    &lt;match url="^robotstxt\.asp$" /&gt;
    &lt;conditions logicalGrouping="MatchAll" trackAllCaptures="false" /&gt;
    &lt;action type="Rewrite" url="robottxt.asp" /&gt;
&lt;/rule&gt;
&lt;rule name="Robots 2" stopProcessing="false"&gt;
    &lt;match url="^robotstxt$" /&gt;
    &lt;conditions logicalGrouping="MatchAll" trackAllCaptures="false" /&gt;
    &lt;action type="Rewrite" url="robottxt.asp" /&gt;
&lt;/rule&gt; </code></pre>
</div>
</div>
</p>
<p>So when I read up I saw about people trying to to do both rules at once or in two sets but it just never managed to work foe me.</p>
<p>I need non http requests to go to https
and for non www requests to go to <a href="http://www.example.com" rel="nofollow noreferrer">www.example.com</a> e.g <a href="https://www.example.com" rel="nofollow noreferrer">https://www.example.com</a></p>
<p>At the moment it's partially working but only because I am not trying the non www. redirects.</p>
<p>I have 2 bindings for the <a href="http://www.example.com" rel="nofollow noreferrer">www.example.com</a> hostnames and this one rule at the top.</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;rule name="Redirect to HTTPS" stopProcessing="true"&gt;
  &lt;match url="(.*)" /&gt;
  &lt;conditions logicalGrouping="MatchAll" trackAllCaptures="false"&gt;
    &lt;add input="{HTTPS}" pattern="^OFF$" /&gt;
  &lt;/conditions&gt;
  &lt;action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" /&gt;
&lt;/rule&gt;</code></pre>
</div>
</div>
</p>
<p>So all the rules are working including the http to https. However I need non www rules to work as well.</p>
<p>To get it to keep the rest of my rules AND to get it to ALSO redirect non www. traffic to <a href="http://www.example.com" rel="nofollow noreferrer">www.example.com</a> e.g <a href="https://www.example.com" rel="nofollow noreferrer">https://www.example.com</a>. What is the best way to do this.</p>
<ol>
<li>Do I need another pair of bindings set up without www. e.s example.com for 80/443?</li>
<li>Then, what rules do I add in and what order do they need to be as int .htacces they are processed top to bottom in loops an I just wonder with IIS way there is also a logical path that could trip it over causing infinite loops.</li>
</ol>