Last Updated on April 14, 2021 by Amit
Cloudflare http to https using RewriteRule
Cloudflare has its own variable to check URL scheme. If you are using cloudflare then your normal htaccess http to https redirect can fail to work. One possible reason behind this is that cloudflare uses %{HTTP:CF-Visitor} variable to check the requested URL scheme while on Apache we use %{HTTPS} for the same purpose.
To enforce SSL on a cloudflare enabled domain, the correct working rule is :
RewriteEngine on
RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"'
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
You just need to replace RewriteCond %{HTTPS} off with RewriteCond %{HTTP:CF-Visitor} ‘”scheme”:”http”‘ in your existing code to make it work.