How can I have CodeIgniter load specific pages using SSL? I have an apache2/mode_ssl
server. mod_ssl
uses a different document root than non-secure
This is what worked for me. Our server both have $_SERVER['SERVER_PORT'] and $_SERVER['HTTP_X_FORWARDED_PORT']
We should check first if $_SERVER['HTTP_X_FORWARDED_PORT'] is available and use this instead of $_SERVER['SERVER_PORT']
$config['base_url'] =
( ( ( empty($_SERVER['HTTP_X_FORWARDED_PORT']) ? $_SERVER['SERVER_PORT'] : $_SERVER['HTTP_X_FORWARDED_PORT'] ) == 443 ? 'https' : 'http') . "://" . $_SERVER['HTTP_HOST'] )
. str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']) ;
tested this on our linux server...
btw, it's based on skyler's answer before which was.
$config['base_url'] = ($_SERVER['SERVER_PORT'] == 443 ? 'https' : 'http') . "://{$_SERVER['HTTP_HOST']}/";