【问题标题】:.htaccess no SSL only on home but SSL everywhere else?.htaccess 只在家里没有 SSL,但在其他地方没有 SSL?
【发布时间】:2012-10-25 23:38:09
【问题描述】:

我希望 .htaccess 不要在主链接上添加 SSL

http://domain.com

但在网站的所有其他链接上

https://domain.com/folder/index.html

所以只有主页是不安全的。最好的 .htaccess 配置是什么?

谢谢

【问题讨论】:

    标签: .htaccess


    【解决方案1】:

    使用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]
    

    【讨论】:

      【解决方案2】:

      通过httpd.conf启用mod_rewrite和.htaccess,然后把这段代码放到你.htaccessDOCUMENT_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]
      

      【讨论】:

        猜你喜欢
        • 2014-05-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-03-19
        • 2010-12-09
        • 1970-01-01
        相关资源
        最近更新 更多