编程语言
首页 > 编程语言> > php一句代码让http跳转https

php一句代码让http跳转https

作者:互联网

//其他框架请加到入口某共公加载的文件中
//方法一 https状态
if(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off'){
    Header("HTTP/1.1 301 Moved Permanently");
    header('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
}
//方法二 判断端口
if($_SERVER['SERVER_PORT']=="80"){
    Header("HTTP/1.1 301 Moved Permanently");
    header('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
}

标签:HTTP,1.1,SERVER,header,Permanently,https,跳转,http
来源: https://www.cnblogs.com/trip-j/p/php.html