How to configure Nginx so it will treat '?…' as part of the file name

Nginx is serving only static files, yet, some of file names contains '?'. Yes, the question mark.

All URLs that contains '?' yield 404 even though file actually exists. e.g.

> GET /foo?lang=ar.html HTTP/1.1
...
...
< HTTP/1.1 404 Not Found

While a file named foo?lang=ar.html does exists in the expected location.

I wonder if there is a way to tell Nginx to treat the entire request as URL including what is currently translated as query string.

The only solution I have in mind is to write a small web server that does this and have nginx reverse proxy that web server, but I prefer get it done with nginx alone.


You can use try_files with either $request_uri or $uri$is_args$args depending on whether you want to have the urlencoded bits decoded or not when looking for the filename.