Skip to content
World Wide Web Server edited this page Jul 4, 2012 · 6 revisions

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. [b]Important Note:[/b] Your base_url must be set to "/" in your config file. This code will live in your .htaccess file.

An entry:

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

An exit: [code]RewriteCond %{SERVER_PORT} !80 RewriteCond %{REQUEST_URI} controller/function RewriteRule ^(.*)$ http://www.yourdomain.com/controller/function[R=301,L][/code]

Duplicate the code for various entry and exit points.

Clone this wiki locally