php网站https怎么做301,php(codeigner)301将http重定向到https

如果站点有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();

}

}

任何帮助都将不胜感激!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值