2012-11-06 146 views
1

我们能否HTTPS仅供主页即对于重定向规则到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} 

回答

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] 
0

您还可以在根级别重定向这样的的.htaccess :

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

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

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