I tried 12 different solutions on this forum and non of them will work. I want all my domains to have https://www.
Now i am using this:
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI}
But now when i go to www.example.com it redirects to https://www.www.example.com (twice www.)
http://example.com works perfect it redirects to https://www.example.com
That's a normal behaviour.
Actually, you'll need to check if www
is in the host or not before doing a redirect.
An easy way would be to split the problem in two conditions
RewriteEngine on
# redirect http://www.example.com to https://www.example.com
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# redirect http(s)://example.com to https://www.example.com
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With