① HTML 的 meta refresh 标签
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="1; url=http://www.baidu.com">
</head>
<body>
</body>
</html>
"1; url = http://www.baidu.com" 代表 1s 以后跳转至百度,http 的状态码是 302。
② JavaScript 的 window.location
<!doctype html>
<html lang="en">
<head>
</head>
<body>
<script>
setTimeout("window.location.href = 'http://www.baidu.com'", 1000);
</script>
</body>
</html>
同样也是 1s 以后跳转至百度,http 状态码也是 302。
③ PHP 的 header
<?php
header('Refresh:1; url=http://www.baidu.com');
?>
1s 以后跳转至百度,http 状态码也是 302。
或者
<?php
header('Location:http://www.baidu.com');
?>
表示直接跳转至百度,http 状态码也是 302。
如果要把 http 状态码改为 301,可以:
<?php
header('Location:http://www.baidu.com', true, 301);
?>