Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

404 Caching returns HTTP 200 status code for 404 pages #197

Closed
raamdev opened this Issue · 4 comments

2 participants

@raamdev
Owner

When the 404 Caching option is enabled, Quick Cache caches the 404 page and serves the cached file upon all subsequent 404 errors. However, it also returns a 200 OK HTTP status code, instead of the proper 404 Not Found.

Here's how you can reproduce this:

  1. Enable 404 Caching
  2. Visit a non-existent page to create a 404 cache file
  3. Run wget --server-response <non-existent page URL> and observe the output
  4. Disable Quick Cache 404 Caching
  5. Run wget --server-response <non-existent page URL> and observe the output

Note that with Quick Cache 404 Caching disabled, WordPress returns the correct HTTP status code.

# ----------- Quick Cache 404 Caching Enabled

$ wget -v http://qcpro.dev/asdasd
--2014-06-05 14:59:23--  http://qcpro.dev/asdasd
Resolving qcpro.dev (qcpro.dev)... 127.0.0.1
Connecting to qcpro.dev (qcpro.dev)|127.0.0.1|:80... connected.
HTTP request sent, awaiting response... 200 OK

# ----------- Quick Cache 404 Caching Disabled

$ wget -v http://qcpro.dev/asdasd
--2014-06-05 15:00:50--  http://qcpro.dev/asdasd
Resolving qcpro.dev (qcpro.dev)... 127.0.0.1
Connecting to qcpro.dev (qcpro.dev)|127.0.0.1|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2014-06-05 15:00:51 ERROR 404: Not Found.

See http://wordpress.org/support/topic/cached-404-returns-200

@raamdev raamdev added this to the Next Release milestone
@jaswsinc
Owner

Ah.. I see. Darn, this actually comes back to the issue with PHP itself, where headers_list() is currently missing the HTTP status code header. Quick Cache would pick this up properly if that were not broken.

From this line in the dev branch.

file_put_contents($cache_file_tmp, serialize(headers_list()).'<!--headers-->'.$cache)

What we could do is stuff the 404 header into the cache file like we already do for the other headers preserved by this line inside the advanced-cache.tpl.php file. In a case where there is a 404 detected, the 404 cache file can include the 404 response header and Quick Cache will repeat this automatically on each subsequent cache hit to that 404; whether it be through a symlink or not.

@jaswsinc
Owner

@raamdev I will have to work with this portion of the code when I work on #56, would you like me to fix this also at the same time?

@jaswsinc jaswsinc was assigned by raamdev
@raamdev
Owner

@jaswsinc Yes, if you could fix this along with #56, that would be great! I've assigned this to you. Thanks!

@jaswsinc jaswsinc referenced this issue
Closed

Feature/197 #219

@raamdev
Owner

Closed by #219.

@raamdev raamdev closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.