对于302 Found
,即临时重定向做:
header('Location: http://www.yoursite.com/home-page.html');
// OR: header('Location: http://www.yoursite.com/home-page.html', true, 302);
exit;
如果你需要一个永久重定向,又名:301 Moved Permanently
,做到:
header('Location: http://www.yoursite.com/home-page.html', true, 301);
exit;
欲了解更多信息检查header function Doc的PHP手册。另外,不要使用header('Location: ');
时,却忘了打电话给exit;
,考虑你正在做一个临时的维护(你不希望搜索引擎索引你的页面),它的建议与自定义消息返回503 Service Unavailable
(即你不需要任何重定向):
<?php
header("HTTP/1.1 503 Service Unavailable");
header("Status: 503 Service Unavailable");
header("Retry-After: 3600");
?><!DOCTYPE html>
<html>
<head>
<title>Temporarily Unavailable</title>
<meta name="robots" content="none" />
</head>
<body>
Your message here.
</body>
</html>
记得在这些头文件后退出你的脚本 – Vitamin 2012-02-20 15:43:34