Last active
March 20, 2019 20:51
-
-
Save Tmeister/2200ad9b5c818fb67ca74dba8f27e724 to your computer and use it in GitHub Desktop.
301 redirections to force naked domain with SSL
This file contains hidden or 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 | |
RewriteCond %{HTTPS} off | |
RewriteCond %{HTTP_HOST} !^(www.)?domain.com$ [NC] | |
RewriteRule . http://domain.com%{REQUEST_URI} [R=301,L] | |
RewriteCond %{HTTPS} on | |
RewriteCond %{HTTP_HOST} !^(www.)?domain.com$ [NC] | |
RewriteRule . https://domain.com%{REQUEST_URI} [R=301,L] | |
#Other option | |
RewriteEngine On | |
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] | |
RewriteRule ^(.*)$ https://%1/$1 [R=301,L] | |
RewriteCond %{HTTPS} off | |
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