skibulk
skibulk

Reputation: 3188

Is it possible to return a 304 Not Modified with .htaccess

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?

Upvotes: 2

Views: 4991

Answers (2)

skibulk
skibulk

Reputation: 3188

An indirect solution:

.htaccess:

RewriteCond %{HTTP:if-modified-since} .
RewriteRule . /not_modified.php [L]

not_modified.php:

header($_SERVER['SERVER_PROTOCOL'].' 304 Not Modified');

Upvotes: 3

Cyclonecode
Cyclonecode

Reputation: 30001

Check out the following links:

  1. http://httpd.apache.org/docs/2.1/caching.html
  2. http://www.chicagostyleseo.com/2010/04/googles-need-for-speed-use-cache-and-htaccess-to-speed-up-your-site/
  3. 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!

Upvotes: 1

Related Questions