title: htaccess rewriteCond using custom http header
body: <p>There are a thousand threads on this but I must be missing something as I can't get it to work.</p>
  <p>My nginx load balancer decrypts SSL traffic and proxies it (via Varnish) through to the content servers. It adds a custom header to the proxied request:</p>
  <pre><code>proxy_set_header &quot;IS-HTTPS&quot; &quot;1&quot;;
  </code></pre>
  <p>I can SEE this HTTP header from the content servers:</p>
  <pre><code>&lt;?php
  var_dump($_SERVER[&quot;HTTP_IS_HTTPS&quot;]);
  ?&gt;
  </code></pre>
  <p>This will output <strong>string(1) &quot;1&quot;</strong> on a HTTPS connection, and <strong>NULL</strong> on a HTTP.</p>
  <p>So, my .htaccess rules:</p>
  <pre><code>RewriteCond %{HTTP:IS_HTTPS} !=&quot;1&quot;
  
  RewriteRule ^(securebit.*)$ https:// %{HTTP_HOST}/$1 [R=301,L]
  </code></pre>
  <p>Doesn't work. Just gets into a redirect loop.</p>
  <p>(NB: the space in &quot;// %&quot; isn't there. StackOverflow validation is falling over on it.)</p>
  <p>Neither do:</p>
  <pre><code>RewriteCond %{HTTP:IS_HTTPS} !=1
  </code></pre>
  <pre><code>RewriteCond %{HTTP:IS_HTTPS} !1
  </code></pre>
  <pre><code>RewriteCond %{HTTP:HTTP_IS_HTTPS} !=&quot;1&quot;
  </code></pre>
  <pre><code>RewriteCond %{HTTP:HTTP_IS_HTTPS} !=1
  </code></pre>
  <pre><code>RewriteCond %{HTTP:HTTP_IS_HTTPS} !1
  </code></pre>
  <p>What simple, obvious and frustrating mistake am I making?</p>