php页面跳转

php只有一种方法,利用JavaScript的window.location是一种方法,利用html的meta的Refresh是一种方法。

代码

php的header

Header("Location: http://www.dreamdu.com/xhtml/");

JavaScript的window.location

echo "<script>window.location=\"http://www.dreamdu.com/xhtml/\";</script>"; 

HTML的meta的refresh

echo "<meta http-equiv=\"refresh\" content=\"0; url=http://www.dreamdu.com/\" />"; 

当时使用php的header方法是也可以为跳转定义html状态码

比如:

Header("HTTP/1.1 301 Moved Permanently");
Header("HTTP/1.1 307 Temporary Redirect");
Header("HTTP/1.1 303 See Other");

html状态码,可以在http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html里查看

如果是永久性的重定向,考虑到seo可以使用下面代码

Header("HTTP/1.1 301 Moved Permanently");
Header("Location: http://www.dreamdu.com/xhtml/");

Random Posts

作者: 可爱的猴子
原载: 可爱的猴子 的blog
版权所有。转载时必须以链接形式注明作者和原始出处及本声明。

发表评论