php中http到https的自动跳转

时间:2017-11-9    作者:晨曦    分类: 源码之家


2a3e8aa3cdf225052fdfef3e02dea8d7.png

做这个的前提是,先自行配置好https环境。


接下来在首页的位置加上


<?php



switch ($_SERVER["HTTP_HOST"]) 

{

case "qqleyi.com": 

header("location:https://qqleyi.com"); 

break;

}



//http转化为https  

if ($_SERVER["HTTPS"] <> "on")

{

    $xredir="https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];

    header("Location: ".$xredir);

}


?>

其它语言以此类推。


当然还可以做302跳转。