黃聰: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']);
}
相關文章
相關標籤/搜索