Don't process requests containing folders

Grant emailgrant at
Mon Sep 12 17:17:06 UTC 2016

My site doesn't have any folders in its URL structure so I'd like to
have nginx process any request which includes a folder (cheap 404)
instead of sending the request to my backend (expensive 404).
Currently I'm using a series of location blocks to check for a valid
request.  Here's the last one before nginx internal takes over:

location ~ (^/|.html)$ {

Can I expand that to only match requests with a single / or ending in
.html like this:

location ~ (^[^/]+/?[^/]+$|.html$) {

Should that work as expected?

- Grant

More information about the nginx mailing list