If a user has a file cached in their browser and they send a http request with an If-Modified-Since
header, is there a way to automatically serve them a 304 Not Modified
response using .htaccess?
Asked
Active
Viewed 4,782 times
2
2 Answers
3
An indirect solution:
.htaccess:
RewriteCond %{HTTP:if-modified-since} .
RewriteRule . /not_modified.php [L]
not_modified.php:
header($_SERVER['SERVER_PROTOCOL'].' 304 Not Modified');

skibulk
- 3,088
- 1
- 34
- 42
1
Check out the following links:
- http://httpd.apache.org/docs/2.1/caching.html
- http://www.chicagostyleseo.com/2010/04/googles-need-for-speed-use-cache-and-htaccess-to-speed-up-your-site/
- http://www.askapache.com/htaccess/apache-speed-last-modified.html
Notice, that from the above link:
If you remove the Last-Modified and ETag header, you will totally eliminate If-Modified-Since and If-None-Match requests and their 304 Not Modified Responses, so a file will stay cached without checking for updates until the Expires header indicates new content is available!

Cyclonecode
- 29,115
- 11
- 72
- 93
-
Correct me if I'm wrong, but it seems that simply clicking the 'refresh' button on the browser will trigger an If-modified-since request regardless of the expires header. – skibulk Dec 21 '11 at 22:54
-
@skibulk - Yes, I think this part is browser specific. I also think it's mentioned in the aboved links. – Cyclonecode Dec 21 '11 at 22:56
-
I thought expires took precedence. So the browser would keep using the cached version until it expired, and then after that use a IfModifiedSince, to prevent double download if it still hasn't changed – Gerben Dec 22 '11 at 21:13