Updated on 08/02/2022
I have set up a custom 404 error page. Below are my htaccess rules.
ErrorDocument 404 /not-found.php RewriteEngine On
After many tests, I realized that it works perfectly for everything except php pages. It works fine if the wrong directory or other file extension is accessed.
Example of link successfully displayed on custom 404 error page
Example of link that cannot be displayed on custom 404 error page
I thought it might be some rewrite rules in my htaccess that were causing the problem, but for testing purposes I've removed them completely and the problem still persists.
I finally found another person who had the same problem and the solution provided solved my problem. This is the question post
The custom 404 error handler in htaccess does not work for non-existent ".php" files
Here is the solution to make the php extension work: