HTTP返回碼301與302的區別


一、簡介

1、301,302 都是HTTP狀態的編碼,都代表着某個URL發生了轉移。 
2、301 redirect: 301 代表永久性轉移(Permanently Moved)。
3、302 redirect: 302 代表暫時性轉移(Temporarily Moved )。
4、301,302對用戶來說沒有區別,他們看到效果只是一個跳轉,瀏覽器中舊的URL變成了新的URL。頁面跳到了這個新的url指向的地方。
5、不同之處,主要在於SEO優化,302好於301。

 

二、實現

1、PHP實現302跳轉

源代碼:

<?php
header("Location: http://yegle.net/recursion.php");
?>

HTTP頭:

HTTP/1.1 302 Found
Date: Fri, 16 Jul 2010 11:26:48 GMT
Server: Apache
X-Powered-By: PHP/5.2.4-2ubuntu5.10
Location: http://yegle.net/recursion.php
Cache-Control: max-age=600
Expires: Fri, 16 Jul 2010 11:36:48 GMT
Vary: Accept-Encoding
Content-Length: 0
Content-Type: text/html

  

2、PHP實現301跳轉

源代碼:

<?php
header( "HTTP/1.1 301 Moved Permanently" );
header( "Location: http://yegle.net/" );
?>

HTTP頭:

HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
Date: Fri, 16 Jul 2010 11:29:07 GMT
Expires: Sun, 15 Aug 2010 11:29:07 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219
X-XSS-Protection: 1; mode=block

 

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM