【问题标题】:How to disable HSTS header with HTTP?如何使用 HTTP 禁用 HSTS 标头?
【发布时间】:2016-11-09 04:22:10
【问题描述】:

我已在我网站的 .htaccess 中插入以下内容,以便加入 HSTS preload list

<ifModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"   
</ifModule>

问题是当我提交我的网站时,我得到:

警告:HTTP 上不必要的 HSTS 标头。 HTTP 页面位于 http://fabriziorocca.it 发送一个 HSTS 标头。这对过去没有影响 HTTP,应该被删除。

目前我在 .htaccess 中使用以下内容以便从 http 切换到 https:

RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

我该如何解决这个问题?

提前谢谢你。

【问题讨论】:

标签: .htaccess http https preload hsts


【解决方案1】:

尝试:

<ifModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" "expr=%{HTTPS} == 'on'"
</ifModule>

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

【讨论】:

  • 这一行对我有用 Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" "expr=%{HTTPS} == 'on'" 它需要在“on”注释上加上单引号:不要删除关键字 always
【解决方案2】:

我在 htaccess 中添加的内容非常适合我。

RewriteEngine On
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
# [NC] is a case-insensitive match
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


# Use HTTP Strict Transport Security to force client to use secure connections only
Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" "expr=%{HTTPS} == 'on'"

env=HTTPS 现在不工作了。

【讨论】:

    【解决方案3】:

    在您的重定向规则下方添加代码:

    Header always set Strict-Transport-Security "max-age=31536000; 
    includeSubDomains; preload" env=HTTPS
    

    【讨论】:

      【解决方案4】:

      不... 错误:HTTP 首先重定向到 www http://domain.fr (HTTP) 应在添加 www 子域之前立即重定向到 https://domain.fr (HTTPS)。现在,第一个重定向是https://www.domain.fr/。需要额外的重定向以确保任何支持 HSTS 的浏览器都会记录顶级域的 HSTS 条目,而不仅仅是子域。

      【讨论】:

        猜你喜欢
        • 2016-09-30
        • 1970-01-01
        • 2023-03-05
        • 2014-08-17
        • 2015-12-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多