Ticket #3027 (closed enhancement: fixed)

Opened 6 years ago

Last modified 5 years ago

404 error pages should be forced to not cache

Reported by: _ck_ Owned by: anonymous
Priority: low Milestone:
Component: Template Version: 2.0.4
Severity: minor Keywords: has-patch
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

3027.diff Download (1007 bytes) - added by Nazgul 5 years ago.

Change History

Nazgul5 years ago

  • Keywords has-patch added

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.

  • Milestone changed from 2.1 to 2.0.5

Candidate for 2.0.5 inclusion.

  • Status changed from new to closed
  • Resolution set to fixed

(In [4291]) nocache_headers from _ck_ and Nazgul. fixes #3027

(In [4292]) nocache_headers from _ck_ and Nazgul. fixes #3027

  • Milestone 2.0.5 deleted

Milestone 2.0.5 deleted

Note: See TracTickets for help on using tickets.