I'm trying to write an Nginx config with the following semantics, expressed in hopefully-readable psuedo-config:
location /dir1/ /dir2/ {
if (matches a .php file) {
serve with php
} else if (matches a non-.php file) {
serve as static content
} else {
404
}
} else {
serve with /index.php
}
How do I do this? I have a decent sense of Apache configuration, but I don't have a good enough grasp on Nginx to sort out the semantics of try_files
and location
matching and internal redirects and stuff. Any tips on how I should structure this?
For reference, the mod_rewrite
-based configuration I'm currently using with Apache is
# Any URL not corresponding to a directory gets rewritten to index.php
RewriteCond $1 !^dir1/
RewriteCond $1 !^dir2/
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
# Allow access to files in any of the directories
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ - [L]
# If either step above resulted in a php file, process it
<FilesMatch "\.php$">
SetHandler application/x-httpd-php
</FilesMatch>