It looks like the 404 is due to the directory /directory.php
not existing. Because your RewriteRule
is executed with the condition only that it isn't a real file (%{REQUEST_FILENAME} !-f
), the rule is mistakenly applied for directories, attempting to append .php
. It's easily fixed with a !-d
:
ErrorDocument 404 http://www.example.com/404
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Now, when a directory like /directory
is requested, the default DirectoryIndex
will be used and no rewrite will take place.