Been looking at implementing HSTS in to one of our sites, hoping to validate it on the preload list. But I can't get my head around how it works with the www. Subdomain.
Our site forces secure www.domain.com using this code in the htaccess.
<ifModule mod_headers.c>
Header set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" env=HTTPS
</ifModule>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
This seems to only send headers when calling the www version.
But when validating, obviously you can't validate a subdomain and it needs to be root TLD. So you get this notice:
www.domain.com
is a subdomain. Please preloaddomain.com
instead. (Due to the size of the preload list and the behaviour of cookies across subdomains, we only accept automated preload list submissions of whole registered domains.)
If I remove the "env=https" and add "always" to the htaccess such as :
<ifModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
</ifModule>
I then get it being used across both www and non www but it still doesnt validate as i get this warning:
Warning: Unnecessary HSTS header over HTTP, The HTTP page at domain.com sends an HSTS header. This has no effect over HTTP, and should be removed.
So im stuck as to what I've done wrong, or what i need to do next to make it validate.
Any help appreciated.
Please note. This is a standard Apache server, using htaccess ( because its a shared environment. Using Cpanel.
Header set...
only in the HTTPS VirtualHost for the "top" site, so that it will not apply to the HTTP ones nor the subdomains?