Hello,
We apologize for the issue you are facing with setting the correct response code for your custom 404 page. To ensure that your custom 404 page returns a 404 status code instead of a 200, you will need to configure your web server or use a plugin that allows you to set the appropriate status code.
Here are some steps you can follow:
-
Check Your Theme’s 404.php File: Ensure that your theme has a 404.php file. This file is typically used to display the content of your custom 404 page. If it doesn’t exist, you may need to create one.
-
Modify the Header: In your 404.php file, add the following line at the very top:
This line will set the response code to 404 when this page is accessed.
-
Use a Plugin: If you’re not comfortable editing theme files, you can use a plugin like "Redirection" or similar to manage your 404 pages and ensure they return the correct status code.
-
Check Server Configuration: If the above steps do not work, you may need to check your server settings or contact your hosting provider to ensure that it is configured to return a 404 status code for missing pages.
For more detailed guidance, you can refer to our guide on fixing soft 404 errors.
Thank you for raising this concern! If you have any further questions or need assistance, please reply to this ticket, and a human agent from the Rank Math Support team will assist you further.
Sources:
How to Fix the Submitted URL Seems to Be a “Soft 404” Error » Rank Math
How to Fix Indexing Issues in Google Search Console » Rank Math
Hi,
Your Rank Math Support Bot reply me with a black line at [2. Modify the Header: In your 404.php file, add the following line at the very top:]. So I can’t see what is it
Hello,
Sorry for that.
Can you please confirm if your custom 404 page is created in a PHP file? If so, you may add the code below:
status_header(404);
nocache_headers();
However, if the custom 404 page is created as a regular WordPress page, try adding this in the bottom line of your theme’s functions.php file:
add_action('template_redirect', function(){
if (is_page('trang-404')) {
status_header(404);
nocache_headers();
}
});
Hope that helps.
Thank you for your reply. The code below is working. I appreciate your help
Hello,
We are super happy that this resolved your issue.
If you have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.
Thank you.