What is the nginx version of these .htaccess rules?

pandora asked:

How should I rewrite this htaccess rules to nginx kind of rules:

RewriteCond %{REQUEST_URI} !^/?puppy/index.php$
RewriteRule . /puppy/index.php

My answer:

In nginx, you won’t use a rewrite for this at all. You would use try_files instead. For example:

try_files $uri $uri/ /puppy/index.php;

Or, more likely, try_files along with a named location to handle PHP scripts.

This isn’t something that should be done in isolation; it is an integral part of the entire server block and you should not consider it separately.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.