Improper 404 Error Handling Fix For WordPress 2.5

I’ve upgraded several of my blogs to WordPress 2.5. However, I noticed that two of them didn’t handle 404 (Page Not Found) errors properly after the upgrade. Every invalid URL gets redirected to the index page; worse still, they returned a 200 server response code which tells the browser that the URL is valid!

Another bad outcome of this bug is that your sites won’t get verified in Google Webmaster Tools.

This problem only occurs on WordPress blogs that uses a page (instead of the more common latest posts listing) as the front page. So how can we fix this?

The good news is that this is a known problem for the WP devs and that a patch is already available. The bad news is that this fix will only be released in WP 2.5.1; and the release date is unknown.

You can apply the fix manually by editing the /wp-includes/query.php file. The offending code is on line 922:

if ( ('page' != get_option('show_on_front') ) || ( $reqpage != get_option('page_for_posts') ) ) {

Change it to:

if ( ('page' != get_option('show_on_front') ) || ( $reqpage !==get_option('page_for_posts') ) ) {

Yes, the only change needed is the additional equal sign as highlighted above! Save the file and your WP 2.5 installation should render 404 errors correctly now.

Hope this helps those who are in a similar situation!

Leave a Reply