问题原文
原帖链接 · Ar Rakin · CC BY-SA 4.0
We can force SSL in apache servers with following config:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Here, we tell the apache server that return a 301 Moved Permanently response to the client.
But there is another status 101 Switching Protocols and I think this status code is more suitable since we are switching from plain HTTP to HTTPS.
Am I right? Anything wrong? Which status code should I use?
已采纳解答
原帖链接 · Maximillian Laumeister · CC BY-SA 4.0
The correct status code to use here is without a doubt 301 Moved Permanently.
101 Switching Protocols is an internal status code that a server generally uses to automatically negotiate certain types of connections. It's not used when changing the URL from http to https. If you're curious about how it works, you can read about the 101 status code and the protocol upgrade mechanism on MDN, but you'll never need to know about it as a webmaster.
As a general rule, you should never directly use 100 series status codes unless you are actually developing web server software. The 300 and 400 series codes (especially 301, 302, and 404) are the ones you'll want to pay attention to when running a simple website.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
