0
(0)

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.

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.