I’m trying to use rewrite alongside try_files. Ideally, I would like Nginx to try the raw URI first. If that doesn’t work, then try a controller /controllers/$1.php. Finally, just redirect to the index. This is what I have so far (I’ve sacrificed the ideal order mentioned above for succinctness):
location / {
if (-f /controllers/$uri) {
rewrite ^(.*)$ /controllers/$1.php last;
return 403;
}
try_files $uri $uri/ /index.php;
}
This doesn’t seem to be working, though. Any ideas?
1 Answer