How to set Dynamic base url to https in CodeIgniter?

混江龙づ霸主 提交于 2020-01-10 10:52:30

问题


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.


回答1:


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;



回答2:


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




回答3:


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

this works for me with virtualhost setup.



来源:https://stackoverflow.com/questions/20415025/how-to-set-dynamic-base-url-to-https-in-codeigniter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!