301 Move Permanently 是HTTP协议中的一个状态码(Status Code)。可以简单地理解为该资源已经被永久改变了位置[1],通常会发送HTTP Location来重定向到正确的新位置。
返回301状态码进行跳转被Google认为是将网站地址由HTTP迁移到HTTPS的最佳方法。[2]
根据定义:[3][4][5]
- 如果一个客户端有链接编辑能力,其应当把所有的引用链接重定向到新的URL上。
- 这个响应代码是可以被缓存的。[6][7]
- 除非请求方法是HEAD,否则响应实体应该包含一个小型的超文本,标注一个超链接到新的URL。
- 如果是除了GET和HEAD之外的请求方法,客户端必须在重定向之前询问用户。
客户端发出请求:
GET/blogHTTP/1.1Host:www.example.com
服务器回应,不带Cache-Control头部:
HTTP/1.1301Moved PermanentlyLocation:http://www.example.org/index.asp
服务器回应,带Cache-Control头部:
HTTP/1.1301Moved PermanentlyLocation:http://www.example.org/index.aspCache-control:private; max-age=600
当某些HTTP/1.0客户端收到该状态码时,可能会将POST方法改为GET方法,继续向新地址发出请求,这是错误的实现——故而后续标准引入了HTTP 307。[8]
由于该代码表示页面地址发生了较长久的改变,故Bing[9]和Google[10]等搜索引擎都推荐使用301重定向,以改变搜索引擎中的实际页面地址。
- ^HTTP/1.1: Status Code Definitions. [2014-06-01]. (原始内容存档于2010-03-16).
- ^Secure your site with HTTPS. Google 用户中心. Google. [6 February 2016]. (原始内容存档于2017-12-15).
- ^T., Fielding, Roy; Tim, Berners-Lee,; Henrik, Frystyk,.Hypertext Transfer Protocol -- HTTP/1.0. [2017-07-04]. (原始内容存档于2010-11-30)(英语).
- ^C., Mogul, Jeffrey; Jim, Gettys,; Tim, Berners-Lee,; Henrik, Frystyk,.Hypertext Transfer Protocol -- HTTP/1.1. IETF. [2017-07-04]. (原始内容存档于2018-06-07)(英语).
- ^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)(英语).
- ^How long do browsers cache HTTP 301s?. StackOverflow. [2016-01-21]. (原始内容存档于2016-01-27).
- ^Mark, Nottingham,; Roy, Fielding,; Julian, Reschke,.Hypertext Transfer Protocol (HTTP/1.1): Caching. [2017-07-04]. (原始内容存档于2017-07-07)(英语).
- ^Roy, Fielding,; Julian, Reschke,.Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content. [2017-07-04]. (原始内容存档于2017-05-25)(英语).
- ^How to Use the Site Move Tool. Bing Webmaster Tools. [2017-07-04]. (原始内容存档于2016-03-07).
- ^Change page URLs with 301 redirects - Search Console Help. Google Help. [2017-07-05]. (原始内容存档于2017-07-24)(英语).