Reputation: 6320
I am using this rule to redirect to 404 while there is no such a file on the server
RewriteEngine on
ErrorDocument 404 mydomain.com/404
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]
this is working fine on for example
mydomain.com/no-exiting-file
but not functioning when I have
mydomain.com/no-exiting-folder/
ormydomain.com/no-exiting-folder/no-exiting-file
How can I fix this to cover not only the none existing file but even the none existing folders as well?
Upvotes: 1
Views: 50
Reputation: 133518
Could you please try following, written based on your shown samples. Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
ErrorDocument 404 mydomain.com/404
RewriteCond %{REQUEST_URI} !\.php/?$ [NC]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [QSA,L]
Upvotes: 2