[Plugin: W3 Total Cache] index.html 404 error gets cached
-
It seems that WordPress doesn’t handle the URL
https://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 becauseindex.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 forindex.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 https://example.com/index.html
- index.html file request results in a 404 error
- 404 error page is cached
- all subsequent requests for https://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.
- Requests for index.html should not result in 404 errors.
- 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: https://example.com/"); exit; } ?>
The second needs to be addressed within W3TC.
- The topic ‘[Plugin: W3 Total Cache] index.html 404 error gets cached’ is closed to new replies.