如何在CodeIgniter中将动态基础url设置为https


How to set Dynamic base url to https in CodeIgniter?

我在这篇文章中尝试使用一个动态的基本url:

在CodeIgniter 中设置动态基础Url

但我以前使用http,但现在,我想改为https,我该怎么做?谢谢

在config/config.php中,尝试以下操作:

$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'];

这适用于我的虚拟主机设置。

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

只需使用$config['base_url']='https://'$_服务器['HTTP_HOST']。str_replace(basename($_SERVER['SCRIPT_NAME'])&"$_服务器['SCRIPT_NAME']);