我们可以只为主页制作 https,即
example.com or http://example.com or www.example.com or http://www.example.com
其余所有页面都应以http开头。
我这样试过,但是没用
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} "^/$"
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteRule ^(.*) http://%{HTTP_HOST}%{REQUEST_URI}
最佳答案
没有真正测试过,但应该会变魔术
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/?$ https://%{HTTP_HOST}/ [R,L]
RewriteCond %{SERVER_PORT} ^443$
RewriteRule !^/?$ http://%{HTTP_HOST}%{REQUEST_URI} [R,L]
关于linux - 仅主页从 http 到 https 的重定向规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13252172/