Skip to content

Instantly share code, notes, and snippets.

@kurozael
Created July 17, 2019 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurozael/9d81bebb464aa3ae1e3b01ea57267c19 to your computer and use it in GitHub Desktop.
Save kurozael/9d81bebb464aa3ae1e3b01ea57267c19 to your computer and use it in GitHub Desktop.
How to configure an Apache VirtualHost to redirect HTTP requests to HTTPS without an infinite redirect loop when using CloudFlare with Flexible SSL.

CloudFlare Flexible SSL Rewrite HTTPS for Apache

Requirements

  • Apache
  • CloudFlare
  • Flexible SSL
  • mod_rewrite

Rewrite Config

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTP:CF-Visitor} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment