title: Forcing HTTPS with .htaccess in CodeIgniter
body: <p>My existing <code>.htaccess</code> removes <code>index.php</code> from my URLs perfectly:</p>
  
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
  RewriteEngine On
  RewriteBase /
  
  #'system' can be replaced if you have renamed your system folder.
  RewriteCond %{REQUEST_URI} ^system.*
  RewriteRule ^(.*)$ index.php/$1 [L]
  
  #Checks to see if the user is attempting to access a valid file,
  #such as an image or css document, if this isn't true it sends the
  #request to index.php
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  
  #This last condition enables access to the images and css folders, and the robots.txt file
  RewriteCond $1 !^(index\.php|(.*)\.swf|images|robots\.txt|css|docs|cache)
  RewriteRule ^(.*)$ index.php/$1 [L]
  &lt;/IfModule&gt;
  
  &lt;IfModule !mod_rewrite.c&gt;
  # If we don't have mod_rewrite installed, all 404's
  # can be sent to index.php, and everything works as normal.
  ErrorDocument 404 /application/errors/404.php
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>I need the entire site to run over SSL, and Pagoda Box, my hosting company, has a proprietary <code>.htaccess</code> edit to switch from <code>http</code> to <code>https</code>:</p>
  
  <pre><code>RewriteCond %{HTTP:X-Forwarded-Proto} = http
  RewriteRule (.*) https://%{SERVER_NAME}/$1 [R]
  </code></pre>
  
  <p>It only works if added at the end of the first conditional statement, and it works perfectly at that: it adds <code>https</code> to a naked URL and removes <code>index.php</code>. </p>
  
  <p>However, if you select the <code>s</code> from <code>https</code> in the address bar and delete it, <code>index.php</code> comes back, plus the last segment of the URL is repeated. If I type the full url, beginning with <code>http://</code>, it redirects and works perfectly - only if I place the cursor in front of the <code>s</code> and delete it does the site break.</p>
  
  <p>Any ideas on how to stop this new condition and rule from conflicting with my existing file?</p>