I’ve made a custom 404.php page and tried to make a properly installed 404 redirect in .htaccess.
ErrorDocument 400 /400/index.php
ErrorDocument 401 /401/index.php
ErrorDocument 403 /403/index.php
ErrorDocument 404 /404/index.php
ErrorDocument 405 /405/index.php
ErrorDocument 408 /408/index.php
ErrorDocument 414 /414/index.php
ErrorDocument 500 /500/index.php
ErrorDocument 501 /501/index.php
ErrorDocument 502 /502/index.php
ErrorDocument 503 /503/index.php
ErrorDocument 504 /504/index.php
It works fine and i see my 404 page, when trying to type incorrect links.
But, when i use different website analyzers or seo checkers, i see the same issue with not properly installed 404 page:
Not properly installed 404 page
Not properly installed 404 page
404.php page with this code before <!Doctype>
<?php
header('HTTP/1.1 404 Not Found');
header("Status: 404 Not Found");
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
What can i do wrong? Hosting technical support told me, that everything is properly installed on their side, but they can’t help with SEO questions. Thanks in advance
2
Answers
I've just found a solution. Website for 404 error checker https://websiteadvantage.com.au/404-Error-Handler-Checker gave me such result:
https://phpout.com/wp-content/uploads/2023/05/7JRXC.png
The problem was in firstly redirecting a page, and only then sending a
So i put this:
And deleted 404 response code in 404.php page, as it was not neccessary.
And the result was perfect. Thanks everyone.
It sounds like the issue may be related to the headers you are sending in your 404.php file. When you use the
header()
function to set the HTTP response code to 404, you should not also use theStatus
header, as it can lead to conflicts.Try removing the Status header and simplifying your code to:
Additionally, keep in mind that SEO checkers may be caching previous responses, so it’s possible that even after you’ve fixed the issue, it may take some time for the checkers to recognize the changes.
To redirect all 404 error responses to a specific URL using .htaccess, you can use the following code:
This code turns on the RewriteEngine and sets the ErrorDocument directive to redirect all 404 errors to the specified URL (replace "your-specific-url" with the actual URL you want to redirect to).
Make sure to place this code at the beginning of your .htaccess file, before any other rewrite rules, to ensure that all 404 errors are caught and redirected.