<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>
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/");

本文介绍了三种实现网页重定向的方法:使用PHP的header函数、利用JavaScript的window.location属性以及通过HTML的meta标签。针对不同的应用场景,可以选择合适的方式进行页面跳转,并提供了具体的代码示例。
1375

被折叠的 条评论
为什么被折叠?



