title: Rewrite rule to HTTPS except when on localhost
body: <p>I am using the answer <a href="https://stackoverflow.com/a/15119044/51">given here</a> as the basis for trying to add a rewrite rule to my web.config file. I want it to match any url that is not running on localhost in order to force https. </p>
  
  <p>Here is what I have right now:</p>
  
  <pre><code>&lt;system.webServer&gt;
    &lt;rewrite&gt; &lt;!-- force https - https://stackoverflow.com/a/15119044/51 --&gt;
      &lt;rules&gt;
        &lt;rule name="Redirect HTTP to HTTPS" stopProcessing="true"&gt;
          &lt;match url="^((?!localhost).)*$"/&gt;
          &lt;conditions&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;
      &lt;/rules&gt;
    &lt;/rewrite&gt;
  &lt;/system.webServer&gt;
  </code></pre>
  
  <p>I am trying to use a <a href="https://stackoverflow.com/a/406408/51">negative lookaround</a> in order to only match url's that do not include "localhost" within the url. But this is not working.</p>
  
  <p>So how should this rule be set up in order to only rewrite non-localhost url's?</p>