Nginx
Pretty Routes for
Static HTML

by Eric Fortis

For instance, this URL:

docs.uirig.com/cards

instead of:

docs.uirig.com/cards.html

Alternative A

  • Upload the HTML files without the extension.
  • Then, in Nginx set: default_type 'text/html';

Alternative B (alias alike)

If you need to serve both routes, /cards and /cards.html, in Nginx set: try_files $uri.html $uri =404;

That attempts to find a file with the “.html” extension appended. The caveat is that it won’t send a 301 (redirect) status code. So for SEO purposes it may hurt having two routes. For that, see how to redirect.

Sponsored by: