I manage a little website in a shared hosting LAMP environment: this basically means the only thing I can edit is an htaccess file.
I wanted to add HSTS support (and I did it), but, when I tested my website here for HSTS preload eligibility, I got the following error:
Error: HTTP redirects to www first
http://example
(HTTP) should immediately redirect tohttps://example
(HTTPS) before adding the www subdomain. Right now, the first redirect is tohttps://www.example.
The extra redirect is required to ensure that any browser which supports HSTS will record the HSTS entry for the top level domain, not just the subdomain.
So, I suppose I should redirect users this way:
http://example
(this is what the user enters in the address bar of his browser)https://example
(we redirect him to the HTTPS version of the website)https://www.example
(we redirect him again to the subdomain www)
My current redirect is done this way:
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
I tried to add a redirect before the last line, this way:
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
but I got a "page isn't redirecting properly" error from the browser.
So, what's the proper way to redirect a user from the http version of the website to the https and finally to the https with www? And: are there any risks?