强制转化为https访问

1. PHP的入口文件处理

$scheme = isset($_SERVER['REQUEST_SCHEME']) ? $_SERVER['REQUEST_SCHEME'] : '';

if(($scheme === 'http')){
    header('HTTP/1.1 301 Moved Permanently');
    header('Location:https://'.$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
}

if($scheme == '' && !isset($_SERVER['HTTP_X_FORWARDED_PROTO'])){
    header('HTTP/1.1 301 Moved Permanently');
    header('Location:https://'.$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
}

 

你可能感兴趣的:(php)