On my website, I have the following code to omit the extension of php pages
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]
I also added this code to show custom 404 pages
ErrorDocument 404 /404
Both of these work independently but not when used together. When I visit a dummy link like www.mydomain.com/pagethatdontexist, I want to see my 404 page, instead I see File not found error which is I guess coming from the server, so I'm getting a 404 on 404 apparently.
I've tried moving ErrorDocument
above and below extension remover code, tried /404.php
as well. I also tried creating an exception for 404 like
RewriteCond %{REQUEST_URI} !^/404.php$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Nothing works.
Edit: When extension code is removed and I visit www.mydomain.com/pagethatdontexist I see my 404 page. But if I visit www.mydomain.com/pagethatdontexist.php I see bland File not Found error from the server. Maybe it can give a clue as to what is going on.