WordPress wp-blog-header.php Causes 404 in IE

January 21st, 2009
35 comments WordPress posted by Pete

I ran into a very interesting problem today. WordPress is great as a CMS, but sometimes for special functionality on specific pages you just need to go outside of the shell, but the great thing is, you can still use the framework right? By including

<?php require('./wp-blog-header.php'); ?>

on the top of your page, you still have access to all the WordPress functions and code library.  Which is great, because if your Navigation is built through a WP page hierarchy, you can still have access to it, and any changes in the backend will be reflected on your orphaned page.

All is right with the world.

Or so it seems.  The underlying problem with this is when you include the all encompassing “wp-blog-header.php” it tries to put this page in the framework.  And the way the framework operates when permalinks are in place is completely database driven.  So if an actual file exists in a sub directory, but it isn’t a part of the WordPress hierarchy, WordPress sends out a 404 header.  Now there’s a conflict, because the browser is getting a 404 header, but a file actually exists in the location.  Firefox and some versions of IE interpret this fine, but some versions of IE don’t.  And more importantly, neither does Googlebot… which means you’re page isn’t going to get indexed.

Fortunately, there’s a relatively easy way to get around this.  Basically, don’t include wp-blog-header.  I can already hear the virtual screams:

But but but!  I want the tags!  Isn’t that the whole point?! *anger* *confusion* *lamentations*

It’s definitely the point.  And luckily, there’s a relatively easy way to accomplish this.  Basically, we just want to include the specific functions of WordPress without making this specific page or pages part of the CMS.  So don’t include wp-blog-header.php at the top.  Use this instead:

<?php
       require('./wp-config.php');
       $wp->init();
       $wp->parse_request();
       $wp->query_posts();
       $wp->register_globals();
?>

This will only pull the specific framework functions without putting the page as a part of the whole.  In essence, WordPress won’t look for the corresponding page or post with “/your-sub-directory/”, but you’ll still be able to use all of the functions such as wp_head().

And you thought nonsensical 404’s couldn’t be fun… for shame.

  1. How to Use Wordpress Functions In Your Site The Search Engine Friendly Way « Laboratory Lingo | Industry Forge said on 06/29/09

    [...] at the post by the nice folks at Adrogen (a Denver website design company) and quickly implement the solution they offer. They suggest using the following 5 lines of code to include WordPress instead of just including [...]

  2. Scott said on 11/30/09

    This SOOOOO fixed the issue I was stressing about ALLL weekend. Thank You!!!!!!!!!!

  3. Pete said on 11/30/09

    No problem! Glad it could help!

  4. keithics said on 01/10/10

    thanks a lot! saves my ass! ;)

  5. Josh said on 02/24/10

    This worked for me. Thanks!

    I’m surprised more people haven’t written about this problem. This is the only place I found that mentions it.

  6. Jason said on 05/28/10

    Pete, many thanks, this post helped me out! I’m thinking the same as Josh – amazed I haven’t seen this anywhere else. Was debugging why Googlebot was throwing off 404 errors – wp_blog_header was the reason. Regards, Jason

  7. Pete said on 05/28/10

    Hey Jason,

    Just glad it could help out. Its a really weird bug that hopefully will be corrected with subsequent releases, but if not, at least there’s this :-)

  8. Tom said on 06/10/10

    Brilliant! Thanks.

  9. husani said on 07/19/10

    yes! spent about 30 minutes on this problem … you saved me another 3 hours. :) thanks so much.

  10. Strategerizer said on 08/10/10

    May you live long and prosper my friend!!

    I spent almost three weeks (sadly, I am not exaggerating)on trying to resolve this issue. Did many re-installations, search far and wide, turned so many things upside down trying to get to the bottom of it. Very hard to repro because if the error or the page gets cached, can change behavior…

    THANK YOU!!!

    (…and I so wish I could have found your post earlier)

  11. Strategerizer said on 08/10/10

    So for anyone else having this issue, fix it as Pete says but make sure you empty IE cache before you test it.

    Happy, happy!

  12. Andy Bailey said on 08/22/10

    that just saved me a lot of trouble. Glad I found you on google for “404 when using wp_blog_header.php”

    (thought I’d put that phrase on this page again so you’re up at number one for the next weary soul) :-)

  13. Tom said on 09/02/10

    Great solution to a really perplexing problem. Google will now love my site again. Thanks!

    (FIST BUMP)

  14. Vikas Garg said on 09/23/10

    Thanks buddy!
    This solution has resolved my big problem :)

  15. Ilene said on 11/01/10

    SO glad I found this page via Google (‘wp-blog-header.php 404′ 1st result). I swapped the code in and the plugin works again. Thanks!

  16. devon said on 11/14/10

    awesome, this saved my life.

  17. Adam Leyton said on 01/05/11

    Thanks so much!! This has just fixed a problem that I’ve been working on for a couple of hours!

  18. Dan said on 01/18/11

    I include this code and I am given the following error message:
    Fatal error: Call to a member function init() on a non-object

    I added the following between the require and class calls to fix it:
    $wp =& new WP();

    I am not a wordpress expert so I can not swear by this solution, but it worked for me.

  19. Matt said on 03/11/11

    This post was a lifesaver! Thank you.

  20. Haydyn said on 03/20/11

    DUDE, you are FREAKING LEGEND!

    saved me hours of work.

    Thank you so much!

  21. Jonathan said on 03/21/11

    Why can’t you just do this?

    require(‘./wp-blog-header.php’);
    header(“HTTP/1.1 200 OK”);

    Just re-write the header information before it goes out to the browser and you get access to all the WP functionality?

    Am I missing somthing?

    Cheers,

    Jt.

  22. great stuff said on 03/24/11

    great stuff man. keep sharing these kinds of things.

  23. Roch said on 04/15/11

    What I am looking to do is similar. I am looking to have a static page as well as the blog appear on the main page of my wordpress site. Right now going to the settings section will only allow me to do one or the other. any feedback would be appreciated.

  24. Jugular Kill said on 04/21/11

    you just saved me hours of research. My site is a bit dynamic I wasn’t 100% sure it was a WP issue.

    ThankYou :D

  25. Craig said on 05/21/11

    Works great thanks!

    I have a few old websites that have their own databases and create static HTML pages using their own templates. I’ve been trying to merge those template with Wordpress themes but it seems new problems keep popping up everywhere. Thanks for solving a big one.

  26. James Revillini said on 06/25/11

    I don’t know if this is an equally efficient fix in terms of resources loaded, but another astute WP hacker found that at the time they merged WPMU into WP, the preferred way to include all the WP headers in to load wp-load.php instead of wp-blog-header.php.[1]

    The net result is the following code:

    I’m not sure if the define for WP_USE_THEMES is still necessary but I imagine it would be. So then you have

    [1] http://wordpress.org/support/topic/integrating-wp-in-external-php-pages?replies=22#post-1568731

  27. James Revillini said on 06/25/11

    Your site ate my code … here it is again:

    /* Short and sweet */
    define(‘WP_USE_THEMES’, false);
    require(‘../../../wp-load.php’);

  28. trash said on 07/07/11

    Am I the only one to who this DOES NOT work?
    I tried several different approaches, including this and those in the comments, I am still being redirected to install.php featuring an 404!
    Why?! What is the suppose of this anyway … stupid Wp :(

  29. trash said on 07/07/11

    Okay, my problem factor: I try to include and load wordpress inside my own php class. this seems to be the troublemaker … really dirty fast workaround: require the wp-config.php outside the class and pass the $wp-variable as a parameter to the class/method.
    I’m sure there is a nicer way, but can’t find one at the moment.

  30. Owen Conti said on 07/14/11

    Thank you so much! You just saved me hours of headaches!

    Merci

  31. Paul Hanak Designs said on 08/04/11

    Worked perfectly! It’s funny. I can use the wp-blog-header as long as I am on the home page of my site, but if I use it on a sub page, then it 404s! Either way, this fixed it. Thank you!

  32. don said on 08/30/11

    Thank you so much bro!

  33. Sach said on 09/29/11

    Thanks alot…problem solved in a sec…

  34. OSEC said on 10/03/11

    Thanks so much for this. Site appeared to be working fine but then strange things started happening with Googlebot and Adobe Browserlab, pages not being indexed, but yet seemed to be working okay!?

    I managed to trace the problem using the brilliant Firefox plugin LiveHTTPheaders to be something to do with wp-blog-header.php, I use a different CMS but use Wordpress for the blog section. Luckily, decided to Google the problem and found this! You have saved me from a massive headache, so thanks so much!

  35. theOwl said on 11/14/11

    You are my hero! WOW, I am so glad I found this post.

Leave a Reply