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!

8 responses to “Improper 404 Error Handling Fix For WordPress 2.5”.

  1. Upgraded To WordPress 2.5.1 - HTNet Says:

    [...] very disappointed that the improper 404 handling bug is still in WordPress 2.5.1. Apparently the situation regarding this bug has gotten more [...]

  2. Frank Says:

    I too upgraded to 2.5.1 and it still has the problem, thanks for sharing the excellent fix, worked perfect for me.

  3. david Says:

    Thank you very much for this man, it worked great! That sh*t was driving me crazy… :)

  4. cubus Says:

    Hi, I used the fix above and at first glance it seemed to be working just fine, but then I noticed it messed up an additional loop I made. Now that loop gives me an 404 page instead…

    Any idea why this is going wrong?

    I’m using wp2.5.1 and k2rc-6 theme.

    Thanks

  5. 工作達人 » Blog Archive » Improper 404 Error Handling Fix For WordPress 2.5 Says:

    [...] 我在改用固定連結的方式在我的部落格,可世醫值發生404找不到網頁的錯誤,後來在Improper 404 Error Handling Fix For WordPress 2.5發現原來是Woedpress 2.5.1的一個錯誤,Orz! [...]

  6. M-M-J Blog - 存在しないURL3 Says:

    [...] 下記に解決法が載っています。 Improper 404 Error Handling Fix For WordPress 2.5 [...]

  7. Alfred Says:

    I have this problem on one of my new sites. Its WP 2.6 but still has the problem, any fix ?

  8. Improper 404 Error Handling Fix For WordPress 2 5 HTNet | debt settlement program Says:

    [...] Improper 404 Error Handling Fix For WordPress 2 5 HTNet Posted by root 16 minutes ago (http://www.heritage-tech.net) I 39 ve upgraded several of my blogs to wordpress 2 5 7 responses to improper 404 error handling fix for wordpress 2 5 potential web malware warning blockoo com 69 do not use hong leong credit cards htnet is 2007 azmeen afandi and is proudly powered by wo Discuss  |  Bury |  News | Improper 404 Error Handling Fix For WordPress 2 5 HTNet [...]