php做301跳转的方法:
方法一:
把http://www.baidu.com原来所有的url都转到http://baidu.com新的地址上,代码如下:
$the_host = $_SERVER['HTTP_HOST'];
$request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
if($the_host == 'www.baidu.com')
{
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://baidu.com'.$request_uri);//
}
?>
方法二:
单页多站的php301重定向代码,www.baidu.com和baidu.com则301到index.php上,yisu.com则301到www.yisu.com上,否则转到错误页,代码如下:
if(($HTTP_HOST=="www.baidu.com")or($HTTP_HOST=="baidu.com"))
{
header("HTTP/1.1 301 Moved Permanently");
Header("Location: /index.php");
}
elseif($HTTP_HOST=="yisu.com")
{
header("HTTP/1.1 301 Moved Permanently");
Header("Location: www.yisu.com");
}
else
{
Header("Location: /404.htm");
}
?>