简体   繁体   中英

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.

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;

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

this works for me with virtualhost setup.

您可以在 pre_controller 中使用codeigniter 钩子,您只需通过字符串替换将 base_url http 更改为 https 并设置基本 url

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM