问题原文
原帖链接 · oucil · CC BY-SA 4.0
I'm looking to add the HSTS header in Apache...
# HSTS / Header Strict Transport Security
Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"
... but I have a long list of vhosts for different but related sites/sub-sites. I'd rather not have to define it in every one of my vhost definitions, but I'm not aware of a way to include a setting in the main https.conf that ONLY applies to the 443 / https versions of those vhosts since it raises warnings in validators when you apply HSTS to a standard 80 / http site.
I've tried wrapping it in <IfModule mod_ssl.c>...</IfModule> tags but if I'm not mistaken, this is really just asking Is the SSL module loaded? I tried searching lots of different ways, but when you don't know the term your looking for, it's difficult to sort through all the static. Any suggestions? Thanks!
已采纳解答
原帖链接 · Esa Jokinen · CC BY-SA 4.0
You can do this with the <If> Directive and the Expressions available; request related variables:
REQUEST_SCHEME: The scheme part of the request's URI<If "%{REQUEST_SCHEME} == 'https'"> Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains" </If>HTTPS:onif the request uses https,offotherwise<If "%{HTTPS} == 'on'"> Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains" </If>
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
