PHP 301跳转代码示例

301跳转

header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.url.com' . $_SERVER['PHP_SELF']  . $request_uri);

 
加强版(有判断)

$the_host = $_SERVER['HTTP_HOST'];
$request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
if($the_host !== 'www.demo.com') {
    //echo $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
    header('HTTP/1.1 301 Moved Permanently');
    header('Location: http://www.demo.net' . $_SERVER['PHP_SELF']  . $request_uri);
}

你可能感兴趣的:(php,301重定向,跳转)