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.5655pk.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.5655pk.com");
}
else
{
Header("Location: /404.htm");
}
?>