HTTP 301

本页使用了标题或全文手工转换
维基百科,自由的百科全书

301 Move PermanentlyHTTP协议中的一个状态码(Status Code)。可以简单地理解为该资源已经被永久改变了位置[1],通常会发送HTTP Location重定向到正确的新位置。

返回301状态码进行跳转被Google认为是将网站地址由HTTP迁移到HTTPS的最佳方法。[2]

定义[编辑]

根据定义: [3][4][5]

  • 如果一个客户端有链接编辑能力,其应当把所有的引用链接重定向到新的URL上。
  • 这个响应代码是可以被缓存的。[6][7]
  • 除非请求方法是HEAD,否则响应实体应该包含一个小型的超文本,标注一个超链接到新的URL。
  • 如果是除了GET和HEAD之外的请求方法,客户端必须在重定向之前询问用户。

例子[编辑]

客户端发出请求:

GET /blog HTTP/1.1
Host: www.example.com

服务器回应,不带Cache-Control头部:

HTTP/1.1 301 Moved Permanently
Location: http://www.example.org/index.asp

服务器回应,带Cache-Control头部:

HTTP/1.1 301 Moved Permanently
Location: http://www.example.org/index.asp
Cache-control: private; max-age=600

客户端实现问题[编辑]

当某些HTTP/1.0客户端收到该状态码时,可能会将POST方法改为GET方法,继续向新地址发出请求,这是错误的实现——故而后续标准引入了HTTP 307[8]

搜索引擎优化[编辑]

由于该代码表示页面地址发生了较长久的改变,故Bing[9]Google[10]等搜索引擎都推荐使用301重定向,以改变搜索引擎中的实际页面地址。

相关条目[编辑]

参考文献[编辑]

  1. ^ HTTP/1.1: Status Code Definitions. [2014-06-01]. (原始内容存档于2010-03-16). 
  2. ^ Secure your site with HTTPS. Google 用户中心. Google. [6 February 2016]. (原始内容存档于2017-12-15). 
  3. ^ T., Fielding, Roy; Tim, Berners-Lee,; Henrik, Frystyk,. Hypertext Transfer Protocol -- HTTP/1.0. [2017-07-04]. (原始内容存档于2010-11-30) (英语). 
  4. ^ C., Mogul, Jeffrey; Jim, Gettys,; Tim, Berners-Lee,; Henrik, Frystyk,. Hypertext Transfer Protocol -- HTTP/1.1. IETF. [2017-07-04]. (原始内容存档于2018-06-07) (英语). 
  5. ^ J., Leach, Paul; Tim, Berners-Lee,; C., Mogul, Jeffrey; Larry, Masinter,; T., Fielding, Roy; James, Gettys,. Hypertext Transfer Protocol -- HTTP/1.1. [2017-07-04]. (原始内容存档于2011-03-07) (英语). 
  6. ^ How long do browsers cache HTTP 301s?. StackOverflow. [2016-01-21]. (原始内容存档于2016-01-27). 
  7. ^ Mark, Nottingham,; Roy, Fielding,; Julian, Reschke,. Hypertext Transfer Protocol (HTTP/1.1): Caching. [2017-07-04]. (原始内容存档于2017-07-07) (英语). 
  8. ^ Roy, Fielding,; Julian, Reschke,. Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content. [2017-07-04]. (原始内容存档于2017-05-25) (英语). 
  9. ^ How to Use the Site Move Tool. Bing Webmaster Tools. [2017-07-04]. (原始内容存档于2016-03-07). 
  10. ^ Change page URLs with 301 redirects - Search Console Help. Google Help. [2017-07-05]. (原始内容存档于2017-07-24) (英语). 

外部链接[编辑]