Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
remove html extension and trailing slash with nginx
server {
listen 80;
server_name *;
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;

This comment has been minimized.

Copy link
Owner Author

Jerry-Lau commented Aug 30, 2017

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
You can’t perform that action at this time.