【发布时间】:2018-12-26 13:14:06
【问题描述】:
如果网站有 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();
}
}
任何帮助将不胜感激!
【问题讨论】:
标签: php codeigniter redirect server