高级前端
http
【Q136】http 向 https 做重定向应该使用哪个状态码

http 向 https 做重定向应该使用哪个状态码

Issue 欢迎在 Gtihub Issue 中回答此问题: Issue 137 (opens in a new tab)

Author 回答者: shfshanyue (opens in a new tab)

一般用作 301 的较为多,但是也有使用 302,如果开启了 HSTS 则会使用 307

如知乎使用了 302,淘宝使用了 301

$ curl --head www.zhihu.com
HTTP/1.1 302 Found
Date: Tue, 24 Dec 2019 00:13:54 GMT
Content-Length: 22
Connection: keep-alive
Server: NWS_TCloud_IPV6
Location: https://www.zhihu.com/
X-NWS-LOG-UUID: 0e28d9a1-6aeb-42cd-9f6b-00bd6cf11500
 
$ curl --head www.taobao.com
HTTP/1.1 301 Moved Permanently
Server: Tengine
Date: Tue, 24 Dec 2019 00:13:58 GMT
Content-Type: text/html
Content-Length: 278
Connection: keep-alive
Location: https://www.taobao.com/
Via: cache20.cn1480[,0]
Timing-Allow-Origin: *
EagleId: 6f3f38a815771464380412555e