nginx try_files, and the rewrite you did not need

A front-controller pattern written with if and rewrite works and is slower and harder to reason about than the two-line version.

# what people write
if (!-e $request_filename) {
    rewrite ^(.*)$ /index.php last;
}

# what it should be
location / {
    try_files $uri $uri/ /index.php?$query_string;
}

# `if` inside a location is evaluated per request and
# interacts badly with almost everything else.

try_files is a single directive evaluated once, and it hands off internally rather than issuing a rewrite that re-enters location matching. The if form is the subject of a well-known page in the nginx documentation titled after the fact that it is considered harmful — the problems are real and are about interaction with other directives rather than about the conditional itself. The query string has to be forwarded explicitly, and omitting it is the classic version of this bug.