仅将主页的规则从http重定向到https

时间:2012-11-06 13:35:05

标签: linux apache security

我们可以只为主页制作https,即

  

example.com http://example.com www.example.com 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}

3 个答案:

答案 0 :(得分:0)

没有经过测试,但应该做出魔术

RewriteEngine On

RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/?$ https://%{HTTP_HOST}/ [R,L]

RewriteCond %{SERVER_PORT} ^443$
RewriteRule !^/?$ http://%{HTTP_HOST}%{REQUEST_URI} [R,L]

答案 1 :(得分:0)

您也可以在根级别的.htaccess中重定向:

DirectoryIndex index.html
Redirect 301 /index.html https://www.website.com/

答案 2 :(得分:0)

这不安全。阅读OWASP a9并设置HSTS flag以使您的整个网站仅限HTTPS。

HTTP是一个错误,如果你为“性能”这样做,你就是个傻瓜。 HTTPS的重量非常轻。

相关问题