Support » Fixing WordPress » 404s are sent with status 200

  • If you go to you’re treated to a “404 not found” page, as you rightly should be – that page doesn’t exist.

    However, the page is served up with a status code of 200 !

    Why this can be a problem: I just moved from MovableType to WordPress. All my old URLs are now invalid, but Google will keep crawling them for a long time. If Google were to get a “404” when it tried to access the old URLs, it would drop them from the cache and stop coming back.

    Instead, search engines are being told by WordPress that those URLs are still valid pages … pages that happen to contain the text “404 page not found … Apologies. There’s been a problem finding the page you’re looking for. “.

    Daniel Drucker

Viewing 9 replies - 1 through 9 (of 9 total)
  • You raise a very important issue!

    Luckily, you can fix this very easily by inserting this code right at the very top of your header.php file:

    if ( !have_posts() ) {
    header ("HTTP/1.1 404 Not Found");

    That obviously needs to be either in an existing php block, or you’ll have to make one, e.g.:

    <?php if ( !have_posts() ) {
    header ("HTTP/1.1 404 Not Found");
    } ?>

    404 pages should already get a 404 header sent along with them. There’s code in WordPress to do just that. if is_404() returns true, then a 404 code is indeed set.

    A bit confused … this occurrs even if I use the default template, so this definitely isn’t due to something a template author has done wrong… what am I not understanding here? This is a bug in WordPress, no? If not, then why isn’t a 404 being sent?

    dmd: I tried it myself with the defaults and looking at my access log, Apache definitely sent a 404 header. How are you seeing that it’s returning 200?

    OHHHHH, my mistake. I get it! I’m sorry. Misunderstanding here.

    Yes, WordPress is sending a 404 header over the wire — but it’s being reported as a 200 in access.log, and not showing up in error.log, because from Apache’s point of view, nothing went wrong — a resource was requested, a resource (the WordPress script) was found to satisfy that request, and anything that happened after that point is not its problem. Right?

    dmd: No, I see actual 404’s in my access.log, not 200’s. If you’re seeing 200’s in Apache’s logs, then it’s sending 200’s. I’m just not certain why it would do that. Try disabling your plugins one by one and see if the problem goes away. I know the plugins don’t seem relevant, try it anyway.

    With no plugins active, if I just telnet from the command line to port 80 of, and type:

    GET /dmd/scents/nosuchpage http/1.1

    it will respond with

    HTTP/1.1 404 Not Found
    Date: Fri, 09 Jun 2006 02:36:49 GMT
    Server: Apache/1.3.33 (Unix) mod_throttle/3.1.2 DAV/1.0.3 mod_fastcgi/2.4.2 mod_gzip/ PHP/4.4.2 mod_ssl/2.8.22 OpenSSL/0.9.7e
    X-Powered-By: PHP/4.4.2
    Transfer-Encoding: chunked
    Content-Type: text/html

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
    <html xmlns="">


    However, that request generated the following line in my access.log: - - [08/Jun/2006:19:36:58 -0700] "GET /dmd/scents/nosuchpage http/1.1" 200 14374 "-" "-"

    So … what gives?

    Stupid mangling/autolinking what I type!

    So … what gives?

    That’s weird, man.

    However, I notice that you’re using FastCGI. I read something regarding 404’s and FastCGI on here just the other day. I think this might be messing with your logs in some odd fashion.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘404s are sent with status 200’ is closed to new replies.