DNB5brims
DNB5brims

Reputation: 30648

How to set Dynamic base url to https in CodeIgniter?

I try the use a dynamic base url in this post:

Set Dynamic Base Url in CodeIgniter

But I used to be use the http, but now, I would like to change to https, how can I do so? Thanks.

Upvotes: 13

Views: 28642

Answers (4)

Manoj Singh
Manoj Singh

Reputation: 53

$config['base_url'] = (isset($_SERVER['HTTPS']) ? "https://" : "http://").$_SERVER['HTTP_HOST'];

this works for me with virtualhost setup.

Upvotes: 2

udin_ordinary
udin_ordinary

Reputation: 1

simply use this $config['base_url'] = 'https://' . $_SERVER['HTTP_HOST'] . str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);

Upvotes: 0

Richat CHHAYVANDY
Richat CHHAYVANDY

Reputation: 597

In your config/config.php, try this:

$root=(isset($_SERVER['HTTPS']) ? "https://" : "http://").$_SERVER['HTTP_HOST'];
$root.= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
$config['base_url'] = $root;

Upvotes: 39

ARIF MAHMUD RANA
ARIF MAHMUD RANA

Reputation: 5186

You can use codeigniter hooks in pre_controller you just change the base_url http to https by string replace and set the base url

Upvotes: 1

Related Questions