Wordpress SEO : Verifying 404 Not-Found headers are not OK
Wordpress also has "404 not found" issues. In the last post we discussed "Drupal SEO : Verifying 404 Not-Found/Forbidden headers are not OK and custom 404 pages" but it seems that this problem persists across CMSes, like Wordpress, that fail to return the right "404 not found" header for a PHP CGI sites. I've checked the latest version of Wordpress and the problem wasn't fixed. So - are you really sure that your Wordpress “404 - page not found” page really returns the “404 not found” header and not “200 OK” or “404 - OK”? I suggest you double check.
Once again, in order to make sure you can use one of the following tools -
- Use an online tool, like - HTTP Header Viewer or HTTP Status Codes Checker.
- Use the Live HTTP headers Firefox plugin.
Track a URL on your site that is suppose to return a “404 not found” message, and check the header. In some cases, like when running PHP CGI server, a wrong header will be returned, like “404 OK” or just "404" instead of "404 not found".
I've looked around and this problem was discussed in regard to the problem of submitting your Wordpress site to Google’s Webmaster Tools which will not accept your Sitemap unless you have valid "404 not found" headers on pages that were not found.
The "404 not found" CGI PHP problem
To overcome the problem, you'll need to change the faulty header('HTTP/1.1 404 Not Found') message to header ('Status: 404 Not Found'). Lookup the Wordpress functions.php in the "status_header( $header )" function and change :
if ( version_compare(phpversion(), '4.3.0', '>=') )
@header("HTTP/1.1 $header $text", true, $header);
else
@header("HTTP/1.1 $header $text");
to :
if ( version_compare(phpversion(), '4.3.0', '>=') )
@header("Status: $header $text", true, $header);
else
@header("Status: $header $text");
(Not a perfect code, I know)
The WP-Cache "404 not found" issue
Please note that there is another issue with file caching through plugins like WP-Cache that will get a 200 OK page on the second load even if the page is a "404 not found" page.
More "404 not found" Wordpress information
Christian Swanson suggests the following with his 404 Header Fix for WordPress Google SiteMaps
So how do you fix it? My friend Carl Hoerth figured it out and it’s actually very easy:
- You find the header.php file in your chosen WordPress theme
- You rename the file header.old
- You open header.old in a text editor
- Insert a blank line one line above the line that reads something like:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional…- Insert:
<?php if (!have_posts()) { header('HTTP/1.0 404 Not Found'); } ?>- Save this edited file as your new header.php
I'm afraid that this won't solve the PHP CGI problem, since it's returning "HTTP/1.0" and not "Status: ", which you can change, but this just goes to show some Wordpress 404 problems and might solve it for other cases.
Further articles on this issue can be found here :





I have the same problem running WP in PHP CGI environment. Your solution works, but still the access.log has it logged "200" instead of "404."
I don't have access to the server code so I can't experiment with them.
Any solution?