Last active
July 24, 2017 23:47
-
-
Save Khodl/4d2d4e74272c75a1719452d632a4acc4 to your computer and use it in GitHub Desktop.
Generic way to force https and redirect to naked domain
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
RewriteEngine On | |
# Remove www (do it first in case https is not supported by subdomain) | |
RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC] | |
RewriteRule ^(.*)$ https://%1/$1 [R=301,L] | |
# Force https... | |
# ... if not local | |
RewriteCond %{SERVER_NAME} !=127.0.0.1 | |
RewriteCond %{SERVER_NAME} !=localhost | |
# ... and not activated | |
RewriteCond %{HTTPS} !=on | |
# ... and proxy (on Heroku, for instance) | |
#RewriteCond %{HTTP:X-Forwarded-Proto} . | |
#RewriteCond %{HTTP:X-Forwarded-Proto} !https | |
# ... Redirect: | |
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment