I have this nginx vhost config:
server {
listen 8081;
server_name blocked_server;
root /home/gian/blocked_server;
access_log off;
error_log off;
index index.php index.html index.htm index.nginx-debian.html;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ / {
try_files $uri $uri /index.php;
}
}
it redirects all urls to index.php except when the url ends with .php extension.
for example this works: http://localhost/somethingthatdontexist
but this returns a 404 and don't redirect to index.php http://localhost/somethingthatdontexist.php
how can i redirect url with .php extension that don't exist to index.php?
try_files $uri /index.php;to yourlocation ~ \.php$block.location ~\.php$block and I can't reload nginx due to this error:nginx: [emerg] "try_files" directive is duplicate in /etc/nginx/snippets/fastcgi-php.conf:5snippets/fastcgi-php.conffile. You can either change thetry_filesstatement in there, or paste the contents of the file into thelocationblock so you can edit it there.