WordPress.org

Forums

404s are sent with status 200 (10 posts)

  1. dmd
    Member
    Posted 9 years ago #

    If you go to http://3e.org/dmd/scents/nosuchpage 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

  2. maerk
    Member
    Posted 9 years ago #

    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");
    } ?>

  3. 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.

  4. dmd
    Member
    Posted 9 years ago #

    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?

  5. 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?

  6. dmd
    Member
    Posted 9 years ago #

    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?

  7. 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.

  8. dmd
    Member
    Posted 9 years ago #

    With no plugins active, if I just telnet from the command line to port 80 of http://www.3e.org, and type:


    GET /dmd/scents/nosuchpage http/1.1
    Host: www.3e.org

    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/1.3.26.1a PHP/4.4.2 mod_ssl/2.8.22 OpenSSL/0.9.7e
    X-Pingback: http://www.3e.org/dmd/scents/xmlrpc.php
    X-Powered-By: PHP/4.4.2
    Transfer-Encoding: chunked
    Content-Type: text/html

    f99
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">

    etc
    etc
    etc

    However, that request generated the following line in my access.log:

    71.224.193.21 - - [08/Jun/2006:19:36:58 -0700] "GET /dmd/scents/nosuchpage http/1.1" 200 14374 "-" "-"

    So ... what gives?

  9. dmd
    Member
    Posted 9 years ago #

    Stupid wordpress.org mangling/autolinking what I type!

  10. 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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags