Last active
March 29, 2018 14:23
-
-
Save joemaller/3cfee1583c3d7ca7069e019787ad93cd to your computer and use it in GitHub Desktop.
Redirect HTTP to HTTPS from .htaccess
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .htaccess redirects can vary depending on server caching, reverse proxies and CDNs | |
# Try these RewriteConditions in order, starting from the top and stepping down | |
# until one works. Only enable one RewriteConds at a time. | |
RewriteEngine On | |
# 1. Try this first | |
RewriteCond %{HTTPS} off | |
# 2. Docs suggest on|off should work, but try this anyway | |
# RewriteCond %{HTTPS} !on | |
# 3. Try port sniffing instead? | |
# RewriteCond %{SERVER_PORT} !=443 | |
# RewriteCond %{SERVER_PORT} 80 | |
# 4. If the above doesn't work, this might (why?) | |
# Known to work on LiquidWeb's Cloud sites | |
# RewriteCond %{ENV:HTTPS} !on | |
# 5. Cloudflare and maybe other CDNs | |
# RewriteCond %{HTTP:X-Forwarded-Proto} =http | |
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