I have .htaccess currently set up to rewrite anything without a period or slash to the equivalent with a .php extension (so \"foo\" internally pulls up \"foo.php\") via the foll
Found a solution:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ (/.*)\.php
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} !^/error\.php
RewriteRule . - [R=404,L,NS]
ErrorDocument 404 /error.php?e=404
Specifically, the third RewriteCond keeps requests for the error page from triggering the RewriteRule (since the THE_REQUEST
still contains the original request (matching the first RewriteCond), and the error page does indeed exist (matching the second RewriteCond).
Note that the third RewriteCond matches the URI format specified for the ErrorDocument. Within error.php, I use $_SERVER["REDIRECT_SCRIPT_URL"]
to find out what file the user originally requested (thus making it look like the 404 was served as a direct response to their request).