nginx rewriting rule for dropping www
I recently wanted to force all traffic from www.mydaddypuzzles.com to mydaddypuzzles.com, effectively dropping the www from the uri. I finally found a post about this here: http://aleksandarsavic.com/nginx-redirect-wwwexamplecom-requests-to-examplecom-or-vice-versa/.
The gist is that you set up a server config for the www site and put in a permanent redirect to the domain.com site.
# This is the redirect server config for www address
server {
server_name www.mydaddypuzzles.com;
rewrite ^(.*) http://mydaddypuzzles.com$1 permanent;
}
# The main config for the domain you are serving
server {
server_name mydaddypuzzles.com;
...rest of config as normal...
}
0 comments
Twitter