Skip to content

Instantly share code, notes, and snippets.

@jerrylau91
Created August 30, 2017 06:50
Show Gist options
  • Save jerrylau91/19e04b3c2681a33bdbacfbb59da15b33 to your computer and use it in GitHub Desktop.
Save jerrylau91/19e04b3c2681a33bdbacfbb59da15b33 to your computer and use it in GitHub Desktop.
remove html extension and trailing slash with nginx
server {
listen 80;
server_name test.com *.test.com;
rewrite ^(/.*)\.html(\?.*)?$ $1$2 permanent;
rewrite ^/(.*)/$ /$1 permanent;
root /path/to/project/root;
index index.html;
try_files $uri/index.html $uri.html $uri/ $uri =404;
error_page 404 /404.html;
error_page 500 502 503 504 /500.html;
}
@jerrylau91
Copy link
Author

use rewrite and try_files directives to achieve two goals, remove the html extension and the trailing slash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment