Last active
September 6, 2018 10:23
-
-
Save xiaohutai/fbf33a0f8c9ed84c36982b278692c2ba to your computer and use it in GitHub Desktop.
.htaccess for no-www and yes-www
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
# -- no-www -- | |
RewriteCond %{SERVER_PORT} ^80$ | |
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L] | |
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] | |
RewriteRule ^(.*)$ https://%1/$1 [R=301,L] | |
# -- yes-www -- | |
RewriteCond %{SERVER_PORT} ^80$ | |
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L] | |
RewriteCond %{HTTP_HOST} !^www [NC] | |
RewriteRule (.*) https://www.%{HTTP_HOST}/$1 [R=301,L] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alternatives, may be: