Reputation: 3262
I'm trying to setup my PHP application in my Raspberry Pi. I'm using a Nginx server to host the application. The SlimPHP requires a .htaccess configuration to redirect all the requests to the index.php file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
I've converted the htaccess using the Winginx tool and edited the /etc/nginx/nginx.conf file adding the following source, but Nginx reported a configuration error:
# nginx configuration
location / {
if (!-e $request_filename){
rewrite ^(.*)$ /index.php break;
}
}
Restarting nginx: nginx: [emerg] unknown directive "location" in /etc/nginx/nginx.conf:98 nginx: configuration file
/etc/nginx/nginx.conf test failed
How should I proceed?
UPDATE
I 've edited the nginx.conf file as recommended but the Nginx still doesn't redirecting the URL. It shows a File not found
answer. Should I edit the nginx.conf file or create any other configuration file?
Upvotes: 0
Views: 492
Reputation: 53533
In general, you want something like this. You can toggle the SLIM_MODE to development as needed.
[Edit: Oops, posted an old version, updated to remove the if.]
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404; # not needed if you have cgi.fix_pathinfo=false in php.ini
include fastcgi_params;
fastcgi_param SLIM_MODE production;
}
Upvotes: 2