I am trying to rewrite an .htaccess rule from Apache to be used on a Nginx server.
RewriteCond $1 !^(index\.php|assets)
RewriteRule ^(.*)$ /index.php/$1 [L]
Here is what I have which is sort of working, but some better direction would be much appreciated. I can hit the index and it loads ok and browse to assets folder fine, but deeper links do not work (PHP program is extracting vars from the URL to build db queries). I know i’m close.. thanks for any replies.
location / {
index index.php;
}
location /$ {
rewrite ^/(.*)$ /index.php/$1 last;
}
location /index.php {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
I think those rules will send everything that isn’t under /assets to /index.php. I think this will do what you want. Also, it moves the root and index directives into the server, which is where they should be to be set as the default for all locations.