• Resolved urban_mainframe

    (@urban_mainframe)


    It seems that WordPress doesn’t handle the URL http://example.com/index.html on an unmodified install (I’ve confirmed this on a handful of other WordPress sites along with my own). This is significant because index.html is a special file on many web-servers, often being the “home” page of a directory on the server. Without special handling, a request for index.html on a WordPress installation generates a 404 (file not found) error — which is obviously something we don’t want our visitors to be presented with.

    Yesterday an unlikely combination of factors resulted in my 404 error page replacing my home page for a complete cache cycle. It went something like this:

    • cached “home” page expires
    • next “home” page request is for http://example.com/index.html
    • index.html file request results in a 404 error
    • 404 error page is cached
    • all subsequent requests for http://example.com/ — and other “home” page URLs — return the cached 404 error page until the cache is next invalidated

    There are two things that shouldn’t have happened here.

    1. Requests for index.html should not result in 404 errors.
    2. Error pages should never be cached.

    The first can be addressed by adding the following code to the beginning of WordPress’ 404.php file:

    <?php
    	if ($_SERVER['REQUEST_URI'] == '/index.html') { header("Location: http://example.com/"); exit; }
    ?>

    The second needs to be addressed within W3TC.

    http://wordpress.org/extend/plugins/w3-total-cache/

Viewing 10 replies - 1 through 10 (of 10 total)
  • Last I checked, WordPress returns a 200 response when it returns it’s 404 page, so it’s impossible for caching plugins to properly handle the case.

    Thread Starter urban_mainframe

    (@urban_mainframe)

    Thanks for responding Frederick. I have checked with Firebug… WordPress is definitely returning a 404 header, not a 200.

    Thread Starter urban_mainframe

    (@urban_mainframe)

    From the WordPress documentation, “Creating an Error 404 Page“:

    Sending Proper Headers
    By default, WordPress continues to send 404 pages as if they were fine. To make search engines like Google spider these pages correctly, you can add this line to the top of your theme’s 404.php file.

    Note: This is no longer required in the latest versions of WordPress

    (Emphasis added)

    Again, I’ll take another look at what can be done.

    I have not got into testing this part of w3tc yet, was the page cached as 404.php or index.html?

    If the former, can one exclude the 404.php file from page caching by adding it to the list of pages in “Never cache the following pages:” on the Page Cache Settings?

    The handing of 404 is actually changed in the next release due to unrelated bug fix. Meanwhile, you can check wp-content/w3-total-cache.config.php and make sure that pgcache.cache.404 is set to false.

    Thread Starter urban_mainframe

    (@urban_mainframe)

    @sqlwiz: It was caching as index.html.

    @frederick: That’s great, thank you.

    This isn’t a show-stopper guys, the code I posted in my original message is enough to prevent this occurring. Maybe just a paragraph in the W3TC documentation, to the effect that the 404.php file should be modified, is all that need be done.

    The net result is that there’s nothing a user will have to do differently if that value is changed in the currently release or in any case in subsequent releases.

    Thread Starter urban_mainframe

    (@urban_mainframe)

    Okay, that’s good to know. Thanks for your time Frederick.

    No problem.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘[Plugin: W3 Total Cache] index.html 404 error gets cached’ is closed to new replies.