#3027 closed enhancement (fixed)
404 error pages should be forced to not cache
Reported by: | _ck_ | Owned by: | |
---|---|---|---|
Milestone: | Priority: | low | |
Severity: | minor | Version: | 2.0.4 |
Component: | Template | Keywords: | has-patch |
Focuses: | Cc: |
Description
I am not certain if this is an internal WP issue but it should at least be used/demonstrated in the default theme 404.php template (more accurately, the header since that's where it has to be fixed).
WP sets regular headers for the 404 error page and this causes most browsers to cache it. So if someone adds a post or fixes whatever issue that cause the url to be invalid, the error doesn't go away unless they realize they need a hard refresh (an easy oversight).
The following code example will prevent the issue in the template header.php but there may be a better way to do it?
<? if (is_404()) { header("HTTP/1.1 404 Not Found"); header ("Pragma: no-cache"); // HTTP 1.0 header ("Expires: Mon, 25 Jul 1995 05:00:00 GMT"); // Date in the past header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified header ("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP 1.1 header ("Cache-Control: post-check=0, pre-check=0", false); // HTTP 1.1 // echo "\n<!--\n"; print_r($_REQUEST); echo "\n-->\n"; } ?>
Attachments (1)
Change History (7)
Note: See
TracTickets for help on using
tickets.
Created a patch which calls nocache_headers whenever a 404 is send.
This should provide a more maintainable way of doing what the reporter wants than on a per theme basis, as he suggested.