304: Not modified and front end caching
Solution 1
This article will answer all your questions on caching
I found that adding
RewriteRule .* - [E=HTTP_IF_MODIFIED_SINCE:%{HTTP:If-Modified-Since}]
RewriteRule .* - [E=HTTP_IF_NONE_MATCH:%{HTTP:If-None-Match}]
To the bottom of my htaccess file (below all rewriterule) worked.
Solution 2
I had this problem and it turned out to simply be that I had Firebug open. This has an option under the Net tab "Disable Browser Cache" that is ticked by default. There is a similar option in Chrome's developer tools, one of the tick boxes on the bar under the menu bar.
Unticking these options resulted in the browser correctly sending HTTP_IF_MODIFIED_SINCE
and everything working fine after all (even with Firebug or Chrome Dev Tools open).
jd.
Updated on June 26, 2022Comments
-
jd. almost 2 years
I am using a PHP script to serve files. I would like to be able to send back a
304
not modified header in my http response if the file has not changed since the client last downloaded it. This seems to be a feature in Apache (and most other web servers), but I have no clue how this can be implemented through PHP.I have heard of using
$_SERVER['HTTP_IF_MODIFIED_SINCE']
, but this variable does not seem to appear in my$_SERVER
super array.My question is not how to return a
304
header, but how to know that one should be returned.
Edit: The problem is that my
$_SERVER['HTTP_IF_MODIFIED_SINCE']
is not set. This is the content of my.htaccess
file:ExpiresActive On ExpiresByType image/jpeg "modification plus 1 month" ExpiresByType image/png "modification plus 1 month" ExpiresByType image/gif "modification plus 1 month" Header append Cache-Control: "must-revalidate" <IfModule mod_rewrite.c> RewriteEngine On RewriteCond $1 !^(controller\.php) RewriteRule (.*\.jpg|.*\.png|.*\.gif) controller.php/$1 </IfModule>
HTTP_IF_MODIFIED_SINCE
still does not appear in the$_SERVER
super array.