Forum Moderators: phranque
RewriteEngine on
RewriteBase /
RewriteEngine On
RewriteCond %{HTTPS} =off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301]
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{HTTP_HOST} ^www.example\.com [NC]
RewriteRule (.*) https://www.example.com/$1 [R=301,L] [edited by: not2easy at 8:09 pm (utc) on Mar 19, 2019]
[edit reason] for readability - please use "example.com" [/edit]
RewriteEngine On
RewriteCond %{HTTPS} =off [OR]
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$ [NC]
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301] is leaving off the www. part - if that code was added by the host, maybe they did not understand what you wanted it to do. Changing it to: RewriteRule (.*) https://www.example.com/$1 [R=301,L] should add it. A domain-name-canonicalization redirect is the last place you want to use %{HTTP_HOST}
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301]
https://www.example.com/https://example.com/foo
A special thanks to phranque for the code snippet! (you totally nailed it)
I can't follow everything, nor get my head completely around this aspect of rewrites, but I keep reading and perhaps it will click eventually..