I'm currently using a rewrite to accept requests for files without including the .php extension, however, I can't find out how to have the requests with .php either be denied or redirected to the friendly version.
For example, this is what I want to accomplish: /contact.php REDIRECT /contact /contact.php (/contact.php exists, but only accessible via /contact) would result in a 403 error
Current config:
location / {
try_files $uri $uri/ @extensionless-php;
index index.php;
}
location ~ .php {
try_files $uri =404;
fastcgi_pass backend;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location @extensionless-php {
rewrite ^(.*)$ $1.php last;
}