2

I usually set up my sites to rewrite URLs in the following cases:

  1. All http traffic is redirected to https (and www), with a 301
  2. All non-www traffic is redirected to www (and https), with a 301

In .htaccess, the rewrite rules are as follows:

RewriteEngine on
RewriteCond %{http_host} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]

RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

Note that all redirects are achieved with only one hop. Non-www traffic goes to www and https, and non-https traffic goes to https and www. How do you achieve the same results in Cloudflare?

P.S. I'm not sure if Cloudflare's "Always Use HTTPS" option is worth enabling since it doesn't use a 301 and I have to write a separate rule for a https redirect rule with a 301 anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.