Skip to content

Instantly share code, notes, and snippets.

@AD7six
Last active June 21, 2016 07:54
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AD7six/5819daf9e5924a343bec to your computer and use it in GitHub Desktop.
Save AD7six/5819daf9e5924a343bec to your computer and use it in GitHub Desktop.
A single redirect for your cloudflare app for http to https, and www.example.com (and olddomain.com etc.) to example.com
# Copy and paste into your .htaccess file or include in your apache conf files
RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"' [OR]
RewriteCond %{HTTP_HOST} !^example.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
# And remember to always use https for future requests
Header set Strict-Transport-Security "max-age=16070400; includeSubDomains"
@DMeechan
Copy link

Does this redirect all subdomains to https://example.com, or just www.example.com?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment