Apache 2.4 – Set Headers for Error Pages in .htaccess

.htaccessapache-2.4http-headers

I am setting some headers using .htaccess for a web page, f. e.:

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

This works fine for usual page access, but the headers are not used on error pages like 404 Not Found and 403 Forbidden.

Is there a way to set Headers for error pages using .htaccess?

Best Answer

Header set Strict-Transport-Security "max-age=31536000; includeSubDomains"

For non-200 OK responses you need to use the always condition:

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

Note that always (as opposed to onsuccess - the default) refers to the internal table of HTTP response headers, it doesn't necessarily mean that it is always set.

Reference:

Related Topic