Force HTTPS (Cloudflare Flexible SSL)

To force HTTPS using Cloudflare Flexible SSL

The best way is to use Cloudflare.

On the Cloudflare website:

  1. Go to “Page Rules” top button
  2. Add new rule: Always use https [ON]

Or you can use in your .htaccess:

RewriteEngine On
# Redirect with www
RewriteCond %{HTTP_HOST} !^www\.yoursite\.com [NC,OR]
# Redirect to https
#    With Cloudflare:
RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"'
#    Without Cloudflare:
# RewriteCond %{HTTPS} off 
RewriteRule ^ https://www.yoursite.com%{REQUEST_URI} [NE,R=301,L]