I am currently using the following in /public_html/.htaccess to strip .php extensions and force trailing slashes.
# Remove .php extension
RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php
RewriteRule (.*)\.php$ /$1/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/(.+)/$
RewriteCond %{DOCUMENT_ROOT}/%1.php -f
RewriteRule ^(.*)/$ $1.php [L]
# Force trailing slash
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .*[^/]$ $0/ [L,R=301]
This works perfectly, however, there are a number of PHP files in subfolders of /public_html that we don't want to be rewritten.
How can I modify the rewrite + trailing slash to apply only to PHP files in the /public_html folder, or, to specify a list of PHP files that the rule applies to?
UPDATE: In my case, I believe the optimal solution will be to strip the PHP extension (and add trailing slash) only to files explicitly specified, rather than creating folder-based conditions.
UPDATE 2: Working solution:
#Remove PHP extension from named files
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(file1|file2)/?$ /$1.php [L,NC]
RewriteEngine On
directive) is unrelated to this issue.