SSL Handling

jdawe edited this page Dec 6, 2012 · 6 revisions
Clone this wiki locally

The Problem: You have certain pages that you want to load through SSL, but you want to continue using CodeIgniter's URL helper.

The Answer: HTTPS Routing with mod_rewrite

We're going to use mod_rewrite to specify entry and exit points for areas of our application that need SSL encryption. When a user hits an entry point, every link created with a URL Helper function will point to an encrypted URL until the user hits an exit point. Important Note: Your base_url must be set to "/" in your config file. This code will live in your .htaccess file.

An entry:

RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} controller/function
RewriteRule ^(.*)$ [R=301,L]

An exit:

RewriteCond %{SERVER_PORT} !80 
RewriteCond %{REQUEST_URI} controller/function
RewriteRule ^(.*)$ [R=301,L]

Duplicate the code for various entry and exit points.