手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆

如何避免网站维护时被搜索引擎“误解” (一)

首页 > PHP >

一般我们在网站维护的时候都会设定一个页面告诉用户,正在维护中,但是怎么样的使用最方便呢?
如果是框架程序的话,最方便了.因为.htaccess中都是指向到 index.php的.在index.php中header跳转一下就OK了

但,究竟怎样写比较好,header怎么写呢?

PHP代码
  1. <?php  
  2. // 301 Moved Permanently  
  3. header("Location: /foo.php",TRUE,301);  
  4.   
  5. // 302 Found  
  6. header("Location: /foo.php",TRUE,302);  
  7. header("Location: /foo.php");  
  8.   
  9. // 303 See Other  
  10. header("Location: /foo.php",TRUE,303);  
  11.   
  12. // 307 Temporary Redirect  
  13. header("Location: /foo.php",TRUE,307);  
  14. ?>  

看着,header是有第三个参数的,为什么要指定参数呢?
The HTTP status code changes the way browsers and robots handle redirects, so if you are using header(Location:) it's a good idea to set the status code at the same time.  Browsers typically re-request a 307 page every time, cache a 302 page for the session, and cache a 301 page for longer, or even indefinitely.  Search engines typically transfer "page rank" to the new location for 301 redirects, but not for 302, 303 or 307. If the status code is not specified, header('Location:') defaults to 302.
当然,一般情况下,都是302...这是第一篇,介绍相对简单一点
还有第二篇,等 我转载好再说,哈哈




本站采用创作共享版权协议, 要求署名、非商业和保持一致. 本站欢迎任何非商业应用的转载, 但须注明出自"易栈网-膘叔", 保留原始链接, 此外还必须标注原文标题和链接.

« 上一篇 | 下一篇 »

发表评论

评论内容 (必填):