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);
}
阅读 2.3k

推荐阅读
The code
用户专栏

The code

47 人关注
65 篇文章
专栏主页