Last active
February 1, 2016 19:47
-
-
Save alexander-ae/cdfe1f4323b598e55ea5 to your computer and use it in GitHub Desktop.
nginx/apache redirect www and 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
Nginx no-www to www | |
------------------- | |
server { | |
#listen 80 is default | |
server_name www.example.com; | |
return 301 $scheme://example.com$request_uri; | |
} | |
server { | |
#listen 80 is default | |
server_name example.com; | |
## here goes the rest of your conf... | |
} | |
Redirect both, non-SSL and SSL to their non-www counterpart: | |
------------------------------------------------------------ | |
server { | |
listen 80; | |
listen 443 ssl; | |
server_name www.example.com; | |
return 301 $scheme://example.com$request_uri; | |
} | |
server { | |
listen 80; | |
listen 443 ssl; | |
server_name example.com; | |
# rest goes here... | |
} |
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
LoadModule mod_alias modules/mod_alias.so | |
<VirtualHost *> | |
ServerName www.example.com | |
Redirect 301 / http://example.com/ | |
</VirtualHost> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment