title: Forcing SSL for all but one directory in CodeIgniter with .htaccess
body: <p>I realize that there's been a lot of questions along these lines but at this point I've read through nearly all of them and I think my situation is unique.  </p>
  
  <p>I'm basically trying to use .htaccess to force HTTPS for everything but make it optional for one directory (which is called pirate).  I've done things like this before but this time it didn't cooperate.  First I started with this code which successfully forces everything to use HTTPS.</p>
  
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
    RewriteEngine On
    RewriteBase /
  
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
  
    RewriteCond $1 !^(blog|images|css|js|robots\.txt|favicon\.ico)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php?/$1 [L]
  &lt;/IfModule&gt;
  &lt;IfModule !mod_rewrite.c&gt;
    ErrorDocument 404 /index.php
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>Then I added the exception (I'm showing just the first rule here):</p>
  
  <pre><code>RewriteCond %{SERVER_PORT} 80
  RewriteCond %{REQUEST_URI} !^(/pirate/) [NC]
  RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
  </code></pre>
  
  <p>That should do it! All controllers should go to HTTPS:</p>
  
  <pre><code>1) http://www.mysite.com/contact/ -&gt; https://www.mysite.com/contact
  </code></pre>
  
  <p>Check. My pirate controller should also be able to do HTTPS:</p>
  
  <pre><code>2) https://www.mysite.com/pirate/ -&gt; https://www.mysite.com/pirate/
  </code></pre>
  
  <p>No change.  Perfect!  Lastly the pirate controller should be able to do good old HTTP:</p>
  
  <pre><code>3) http://www.mysite.com/pirate/ -&gt; https://www.mysite.com/index.php?/pirate/
  </code></pre>
  
  <p>That's not right.  It still forces HTTPS and it stopped hiding the index.php.  So to summarize, I have two conditions and a rule. It seems like if the first condition is true and the second one is false then the rule is applied and then the second rule is applied and THEN the 301 redirect is returned.  I know that sounds strange but if it wasn't I wouldn't be asking.</p>
  
  <p>Why is this happening and how do I fix it?</p>