Ticket #3027 (closed enhancement: fixed)

Opened 2 years ago

Last modified 2 years ago

404 error pages should be forced to not cache

Reported by: _ck_ Assigned to: 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 (1.0 kB) - added by Nazgul on 09/30/06 23:12:19.

Change History

09/30/06 23:12:19 changed by Nazgul

  • attachment 3027.diff added.

09/30/06 23:16:06 changed by Nazgul

  • keywords set to has-patch.

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.

10/04/06 03:17:41 changed by Nazgul

  • milestone changed from 2.1 to 2.0.5.

Candidate for 2.0.5 inclusion.

10/04/06 03:54:12 changed by markjaquith

  • status changed from new to closed.
  • resolution set to fixed.

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

10/04/06 03:55:05 changed by markjaquith

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

11/30/06 19:41:51 changed by

  • milestone deleted.

Milestone 2.0.5 deleted