php301重定向
于 2024-04-28 发布 阅读量89
//强制https
if(!isset($_SERVER['HTTPS'])||$_SERVER['HTTPS']=='off'){
header("HTTP/1.1 301 Moved Permanently");
header('Location:https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
}
// 强制跳转到www
$host = $_SERVER["HTTP_HOST"];
$host = trim($host);
if ($host != 'www.aaa.com'){
header('HTTP/1.1 301 Moved Permanently');
$url = isset($_SERVER["REQUEST_URI"]) ? $_SERVER["REQUEST_URI"] : '';
header('Location:https://www.aaa.com' . $url);
} 