I have a static site served via nginx, but I don't like seeing .html in the URLs.
It's a little tricky serving a static site without the .html extension because you may have a directory and an html page with the same name.
The way to deal with that is to actually use the .html extension in the file system but not URLs.
location / { if ($uri ~ ^/google) { break; } if ($uri ~ ^/y_key_) { break; } if ($uri ~ \.html$) { return 404; } if ($uri = /index) { return 404; } if (!-f $request_filename) { rewrite ^/$ /index.html break; rewrite .* $uri.html break; } }
Writing clean URLs is much easier with try_files, which allows you to do something like
try_files $uri.html
Wouldn't something like this accomplish the same thing? (Sorry if I'm totally wrong, I'm not really good)
location /google/ { } location /y_key_/ { } location ~ \.html$ { return 404; } location = /index { return 404; } location / { try_files $uri @rewrite } location @rewrite { rewrite ^/$ /index.html break; rewrite .* $uri.html break; }
I have a static site served via nginx, but I don't like seeing .html in the URLs.
It's a little tricky serving a static site without the .html extension because you may have a directory and an html page with the same name.
The way to deal with that is to actually use the .html extension in the file system but not URLs.