We have an Apache 2.4 server that runs numerous virtual hosts, some of which use http and some of which use https. I would like to send the same HSTS (Strict-Transport-Security) header only in those virtual hosts that use https.

I realize I could add the Header command individually to each virtual hosts, but I would rather set it once in the Apache global config section. Is it possible to set it in the global config so that only the https virtual hosts send it?


You can try to use a if expression.



For example, untested

# Check a HTTP header for a list of values <If "%{HTTPS} == 'on' && %{HTTP_HOST} == 'ssl.example.com'"> Header set HSTS ... </If>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.