PHP的301重定向代码

一、这种方法,因为它可以把www.seosir.cc原来所有的url都转到seosir.cc新的地址上

<?php
$the_host = $_SERVER[‘HTTP_HOST’];
$request_uri = isset($_SERVER[‘REQUEST_URI’]) ? $_SERVER[‘REQUEST_URI’] : ”;
if($the_host == ‘www.seosir.cc’)
{
header(‘HTTP/1.1 301 Moved Permanently’);
header(‘Location: http://seosir.cc’.$request_uri);//
}
?>

二、单页多站的php301重定向代码,www.seosir.cc和seosir.cc则301到index.php上,www.seosir.cc则301到seosir.cc上,否则转到错误页

<?php
if(($HTTP_HOST==”www.seosir.cc”)or($HTTP_HOST==”seosir.cc”))
{
header(“HTTP/1.1 301 Moved Permanently”);
Header(“Location: /index.php”);
}
elseif($HTTP_HOST==”www.seosir.cc”)
{
header(“HTTP/1.1 301 Moved Permanently”);
Header(“Location: http://seosir.cc”);
}
else
{
Header(“Location: /404.htm”);
}
?>

讨论区