对于302 Found
,即临时重定向,请执行以下操作:
header('Location: http://www.example.com/home-page.html');
// OR: header('Location: http://www.example.com/home-page.html', true, 302);
exit;
如果您需要永久重定向(又名:301 Moved Permanently
),请执行以下操作:
header('Location: http://www.example.com/home-page.html', true, 301);
exit;
有关更多信息,请查看PHP手册中的header function Doc.另外,使用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>