Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tannnt810/6db6620de7553f6b55919c9fda88a3dc to your computer and use it in GitHub Desktop.
Save tannnt810/6db6620de7553f6b55919c9fda88a3dc 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