Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#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:


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)

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

Download all attachments as: .zip

Change History (6)

9 years ago

#1 @Nazgul
9 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.

#2 @Nazgul
9 years ago

  • Milestone changed from 2.1 to 2.0.5

Candidate for 2.0.5 inclusion.

#3 @markjaquith
9 years ago

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

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

#4 @markjaquith
9 years ago

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

#5 @anonymous
9 years ago

  • Milestone 2.0.5 deleted

Milestone 2.0.5 deleted

Note: See TracTickets for help on using tickets.