实现强制https方案

时间:2018-4-20    作者:晨曦    分类: 源码之家


下面上代码

<?php if ($_SERVER["HTTPS"] <> "on")
{
    $xredir = "https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    header("Location: ".$xredir);
} ?>

代码扔在头部即可!!

下面还有Nigix和Apache的跳转方法

Nigix:

if ($scheme = http ) { return 301 https://$host$request_uri;
}

Apache:

RewriteEngine On RewriteCond %{HTTP:From-Https} !^on$ [NC] RewriteCond %{HTTP_HOST} ^(www.)?abc.com$ [NC] RewriteRule ^(.*)$ https://www.abc.com/$1 [R=301,L]


版权声明
 九月吖 原创