Reputation: 824
I need to find the best rewrite rule for my website...
I have 2 domains example.it and example.com but I have SSL under example.com only.
What I need: each user request should be redirected to https://www.example.com/...
Now I'm using this rule:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example\.it$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
but if I digit http://example.com its redirect me to https://example.com, not www.
Also if I do a GTMetrix test I got an F value under Avoid landing page redirects:
Avoid landing page redirects for the following chain of redirected URLs.
http://example.it/
http://www.example.com/
https://www.example.com/
how can I solve? Thanks.
Upvotes: 1
Views: 166
Reputation: 785581
You can do all this in a single redirect rule and avoid multiple redirects. Have your .htaccess containing this rule only:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L,NE]
Make sure to clear your browser cache when testing this.
Upvotes: 1