Skip to content

Instantly share code, notes, and snippets.

@nghuuphuoc
Last active March 2, 2017 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nghuuphuoc/7884874 to your computer and use it in GitHub Desktop.
Save nghuuphuoc/7884874 to your computer and use it in GitHub Desktop.
Some of useful Nginx rewrite rules
// Nginx redirect non-www to www
server {
listen 80;
server_name domain.com;
rewrite ^/(.*)$ http://www.domain.com/$1 permanent;
}
server {
listen 80;
server_name www.domain.com;
// ...
// leave other settings here
}
// Nginx redirect www to non-www
server {
listen 80;
server_name www.domain.com;
rewrite ^/(.*)$ http://domain.com/$1 permanent;
}
server {
listen 80;
server_name domain.com;
// ...
// leave other settings here
}
// Remove .html
server {
rewrite ^(/.+)\.html$ $scheme://$host$1 permanent;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment