I'm migrating my server from Apache to Nginx and have this very simple .htaccess
rule:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
The idea behind it is to direct every request to a front controller (index.php
). I'm trying to do the same with Nginx. I used an online converter to make this Nginx location block:
location / {
if (!-e $request_filename){
rewrite ^(.*)$ /index.php break;
}
}
but when I add it to my site's configuration Nginx just spits out the source code of the PHP file as a download. For reference, here's the entire configuration file:
I know PHP works, as if I remove the location block and make a file with <?php phpinfo();
it works correctly.
Any help would be appreciated.
Skip end of regexp:
This is how I route EVERYTHING to index.php, including sub-directory requests, HTTP args, ect.
So for example, these get sent to index.php:
While these go directly to files