2012-11-06 143 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的重量非常輕。