I would like to configure our Nginx server to server PHP files without their suffix. The issue is that we have directory in the same name of the file and I don't want to move the file under index.php inside the same directory.
Here is the file structure
/www-root/index.php
/www-root/xyz.php
/www-root/xyz/amit.php
I managed to get the php suffix to be removed and I would like to access both of the urls as follow:
www.example.com/xyz
www.example.com/xyz/amit.php
I don't want to move xyz.php to /xyz/index.php since that way there will be a forward slash at the suffix of the URL (which is something I would like to avoid).
I can access www.example.com/xyz.php but when I'm trying to access www.example.com/xyz it will redirect to www.example.com/xyz/ and will fail on 404.
Below is my Nginx conf file:
location / {
try_files $uri $uri.html $uri/ @extensionless-php;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location @extensionless-php {
rewrite ^(.*)$ $1.php last;
}
Any ideas?