Don't process requests containing folders
Grant
emailgrant at gmail.com
Mon Sep 12 23:32:28 UTC 2016
>> location ~ (^/[^/]*|.html)$ {}
>
> Yes, that should do what you describe.
I realize now that I didn't define the requirement properly. I said:
"match requests with a single / or ending in .html" but what I need
is: "match requests with a single / *and* ending in .html, also match
/". Will this do it:
location ~ ^(/[^/]*\.html|/)$ {}
> Note that the . is a metacharacter for "any one"; if you really want
> the five-character string ".html" at the end of the request, you should
> escape the . to \.
Fixed. Do I ever need to escape / in location blocks?
>> And let everything else match the following, most of which will 404 (cheaply):
>>
>> location / { internal; }
>
> Testing and measuring might show that "return 404;" is even cheaper than
> "internal;" in the cases where they have the same output. But if there
> are cases where the difference in output matters, or if the difference
> is not measurable, then leaving it as-is is fine.
I'm sure you're right. I'll switch to:
location / { return 404; }
- Grant
More information about the nginx
mailing list