Force https://www. for Codeigniter in htaccess with mod_rewrite
You could do it in code instead of using htaccess.
You can create a helper function that will redirect the page to be over SSL, which you call from your controller.
In your helper;
function force_ssl() { if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on") { $url = "https://". $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; redirect($url); exit; }}
Then in your controller;
class Whatever extends CI_Controller { function __construct() { parent::__construct(); $this->load->helper(array('your_ssl_helper')); } public function index() { force_ssl(); ... }}
I think, instead of
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
you should have something like
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
do have the rewrite rule match. Your link is currently produced by the third rule.
Use this
RewriteCond %{SERVER_PORT} 80RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R=301,L]
instead of
RewriteCond %{HTTPS} !=onRewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]