【发布时间】:2012-10-25 23:38:09
【问题描述】:
我希望 .htaccess 不要在主链接上添加 SSL
但在网站的所有其他链接上
所以只有主页是不安全的。最好的 .htaccess 配置是什么?
谢谢
【问题讨论】:
标签: .htaccess
我希望 .htaccess 不要在主链接上添加 SSL
但在网站的所有其他链接上
所以只有主页是不安全的。最好的 .htaccess 配置是什么?
谢谢
【问题讨论】:
标签: .htaccess
使用RewriteRule 匹配/ 之外存在的任何东西,如果匹配,则重写为SSL:
RewriteEngine On
# If ssl is not already active
RewriteCond %{HTTPS} !=on
# .+ matches one or more of any character... An empty string would not match
RewriteRule ^(.+)$ https://%{HTTP_HOST]}%{REQUEST_URI} [L,R=301]
【讨论】:
通过httpd.conf启用mod_rewrite和.htaccess,然后把这段代码放到你.htaccess的DOCUMENT_ROOT目录下:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^.+$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} =on
RewriteRule ^$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
【讨论】: