Forum Moderators: phranque
Header set Strict-Transport-Security "max-age=300; includeSubDomains; preload" env=HTTPS RewriteCond %{HTTPS} !=on
RewriteRule (.*) https://www.example.com/$1 [R=301,L] #URL CANONICALIZATION OF ALL NON-WWW DOMAIN VARIANTS
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9][a-z0-9\-]*[a-z0-9]\.(co\.[a-z]{2}|[a-z]{2,6}))\.?(:[0-9]{1,5})?$ [NC]
RewriteRule (.*) https://www.%1/$1 [R=301,L]
#
#URL CANONICALIZATION OF ALL WWW DOMAIN VARIANTS
RewriteCond %{HTTP_HOST} ^www\.([a-z0-9][a-z0-9\-]*[a-z0-9]\.(co\.[a-z]{2}|[a-z]{2,6}))(\.|\.?:[0-9]{1,5})$ [NC]
RewriteRule (.*) https://www.%1/$1 [R=301,L] Error: HTTP does not redirect to HTTPS
`http://example.com` (HTTP) redirects to `https://www.example.com/`. The first redirect from `http://example.com` should be to a secure page on the same host (`https://example.com`)
#Redirect invalid and non www requests
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) https://www.example.com/$1 [R=301,L] handles both non-www and non https requests. This rule needs to come after all other rewrite rules. Testing for HSTS on hstspreload.org now returns:You are right and the utility is wrong, so maybe you should find a different place to do your testing.
Error: HTTP does not redirect to HTTPS
`http://example.com` (HTTP) redirects to `https://www.example.com/`. The first redirect from `http://example.com` should be to a secure page on the same host (`https://example.com`)
When I installed SSL certificate for the first time, I added this to .htaccess:Did you not already have a domain-name-canonicalization redirect? It should be a single rule, with two OR-delimited conditions: one for not-https and the other for wrong-www. If your redirects are happening in a single step--the spurious “error” you reported earlier--the appropriate rule is probably already in place. Just to repeat it here:
RewriteCond %{HTTPS} !=on
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] I've simplified all of the mentioned redirects to this:Noooo. Now you're going backward. You need a single rule, with two (or more)* conditions. In addition, the domain-name-canonicalization part needs to be expressed as a negative: “anything other than my preferred form” (with closing anchor to allow for requests with appended port number).
Noooo. Now you're going backward. You need a single rule, with two (or more)* conditions.
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [L,NE,R=301] What would be the difference$1 means “reuse material that was captured in the Pattern part of the RewriteRule”.
Would that be a sub-request?Not sure about that, frankly, but I kinda think not, since php stuff is done by its own file, not by the server itself.