I am trying to remove the .php
extension from the URL and at the same time, I have to allow trailing slash. I am attaching my code below. My code successfully removed the .php extension but not adding a trailing slash.
Please help.
location / {
try_files $uri $uri.html $uri/ @extensionless-php;
index index.php;
}
location @extensionless-php {
rewrite ^/(.*)/$ /$1 permanent;
try_files $uri $uri/ $uri.html $uri.php$is_args$query_string;
}
Here are the lines of codes I have added in my nginx.conf
TL;DR
#case :
# 1. example.com/about-us.php => example.com/about-us/
# 2. example.com/about-us => example.com/about-us/
# 3. example.com/about-us?s=search => example.com/about-us/?s=search