如何使用HTTP禁用HSTS头?

5

为了被允许进入HSTS preload列表,我已经在我的网站的.htaccess文件中插入了以下内容:

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

问题在于当我提交我的网站时,我会得到以下提示:

警告:HTTP上不必要的HSTS头。 http://fabriziorocca.it的HTTP页面发送了一个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]

我该如何解决这个问题?

提前感谢你的帮助。


4个回答

1
在您的重定向规则下面添加以下代码:
Header always set Strict-Transport-Security "max-age=31536000; 
includeSubDomains; preload" env=HTTPS

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]

1
这行代码对我有效:Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" "expr=%{HTTPS} == 'on'",其中在 'on' 上需要使用单引号。注意:请勿删除关键字 always - pedrotester

1

我在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现在无法工作。


0

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接