如果站点有SSL证书,我将尝试强制使用HTTPS。我可以确认代码确实有效,因为它确实执行重定向,但最终会无限循环,尽管我不确定为什么。只有当服务器端口不是443时才应该进行重定向,我假设在第一次重定向之后,用户应该使用端口443。
这是我的密码;
// If they're using a masking domain and they own an SSL certificate, force SSL
$this->db->where('client_id', $client['client']);
$result = $this->db->get('ssl_certs')->row_array();
// only run this function if there is a date in this field
if (!empty($result['ssl_completed_date']))
{
// if they're not using https, redirect them to https
if($_SERVER['SERVER_PORT'] != 443)
{
$redirect = 'https://www.' . $_SERVER['HTTP_HOST'] . '/website';
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $redirect);
exit();
}
}
任何帮助都将不胜感激!