: Https redirects + Cloudflare Page Rules missing situation I have just moved my website to https and after some scares it is working, mostly. I did find out that when I input the naked domain
I have just moved my website to https and after some scares it is working, mostly.
I did find out that when I input the naked domain on the browser it is not going to the desired URL, as follows:
typed URL = example.com
redirects to = example.com desired URL = www.example.com
The following Page Rule is set on Cloudflare:
pattern = *example.com/* rule = Forwarding to www.example.com/
On the origin server, the .htaccess file has:
RewriteCond %{HTTPS} off
RewriteRule (.*) %{HTTP_HOST}%{REQUEST_URI} [R=301,L]
What am I missing?
More posts by @Shanna517
1 Comments
Sorted by latest first Latest Oldest Best
%{HTTP_HOST} will refer to whatever host the site was accessed through. ie. example.com or example.com. To always redirect to example.com then simply put this in the substitution:
RewriteCond %{HTTPS} off
RewriteRule .* www.example.com%{REQUEST_URI} [R=301,L]
But unless you had a similar rule before then both example.com and example.com would have been accessible (and possibly indexed). In fact, if you access example.com now it does not redirect to www.example.com. You also need the following, in addition to the above:
RewriteCond %{HTTP_HOST} !www.
RewriteRule .* www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
So, in summary, the first block corrects for HTTP -> HTTPS and the second corrects if the www subdomain is omitted. I also removed the parentheses in your pattern (.*) since you aren't capturing it for the substitution.
These two rule blocks could be combined into one if desired...
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !www.
RewriteRule .* www.example.com%{REQUEST_URI} [R=301,L]
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.