Skip to content

Instantly share code, notes, and snippets.

@alexander-ae
Last active February 1, 2016 19:47
Show Gist options
  • Save alexander-ae/cdfe1f4323b598e55ea5 to your computer and use it in GitHub Desktop.
Save alexander-ae/cdfe1f4323b598e55ea5 to your computer and use it in GitHub Desktop.
nginx/apache redirect www and ssl
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...
}
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