Remove .php extensions with .htaccess without breaking DirectoryIndex

I’m thinking you just need to verify that the file exists prior to doing the rewrite, that way you’ll leave 404 and directoryindex behaviours intact:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

(not tested)

Leave a Comment