I'm trying to create a custom 404 error page.
What I have so far works very well with all unexisting documents, folders, images, htmls, etc. - opens my custom 404 page (with output Custom 404!)
However, when I try to access a file with a .php
extension that does not exist I get this:
...being a "File not found." on the screen, rather than being redirected to my 404 document.
My .htaccess
RewriteEngine On
ErrorDocument 404 /404.php
My 404.php
<?php
header("HTTP/1.0 404 Not Found");
include '404.html';
die();
?>
My 404.html
<!DOCTYPE html>
<html>
<head>
<title>Custom 404 | Not found!</title>
</head>
<body>
Custom 404!
</body>
</html>
EDIT
To be more clear about what is happening here.
I believe paths and .htaccess work just fine but there has to be some trick with php. Here are few examples:
When I try to open some files that do not exist on my server:
php file, you can create one as a simple HTML file with a . php extension and then upload it to your site's theme directory. Any time a 404 error occurs, WordPress will serve up this 404. php page to the user.
404 is the HTTP error number returned when a resource is unable to be located on the server. The PHP code at the top of the above file returns this code to ensure systems such as search engines don't mistake the page for real content.
I suspect the difference is that php files launch the interpreter while html files are just served. A solution that works but might not be the only one or the best one is to add this directive to the host configuration file:
ProxyErrorOverride on
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With