Redirecting to HTTPS and WWW address (non www address redirects to www)

Hello, I’ve looked over the documents and need some help/clarification on my issue. I’m a little stuck with the .htaccess rules and hoping someone with experience can pick up my issue.

I’m using the flexible SSL.

First I set redirection rules .htaccee at my domain. Which caused several redirects and loops. So I deleted everything and set “Page Rules” as follows. > ALWAYS USE SSL
This works great. However, I want the domain without WWW to redirect to WWW.

Example: > Redirects to (Correct) > Redirects to (INCORRECT - I want it to redirect to the version

I tried the following .htacess on my server which worked without Cloudflare:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

I’ve also tried this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^ [NC,OR]
RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301,NC]

Can anyone point out where I’ve gone wrong or if I need to add further rules to identify Cloudflare so that it doesn’t go into a loop.

I understand you can do some of this with forwarding rules in Page Rules. But I would prefer doing this at my server level using .htaccess if possible.And use the page rules instead for bypassing caching etc.


Thank you - that makes perfect sense.
And I didn’t know you could get a free SSL from Cloudflare for the origin. So I will enable the full option with the certificate.

Thanks again.

1 Like

.htaccess redirect www to non-www with SSL/HTTPS
I’ve got several domains operating under a single .htaccess file, each secured via SSL. I need to force https on every domain while also ensuring www’s redirect to non-www’s. Here’s what I’m using which doesn’t work:

RewriteCond %{HTTP_HOST} ^www.%{HTTP_HOST}
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI}/$1 [R=301,L]


should redirect to…

2 posts were split to a new topic: Redirect issue