So I have this site, It has a directory structure like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
If you want to add .php
extension to only files in site root then use:
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/.]+)/?$ $1.php [L]
Here negated character class [^/.]+
will match only file in current directory as it matches 1 or more characters that are not /
and .
However if you want to correctly add .php
to all files then use this rule:
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]