Based on this solution used in this answer on SO-en I created a .htaccess and PHP script
.htaccess:
RewriteEngine On
RewriteCond %{HTTP:if-modified-since} .
RewriteCond %{HTTP:if-none-match} .
RewriteRule . not_modified.php [L]
not_modified.php:
<?php
if (isset($_SERVER['REDIRECT_URL'])) {
$file = $_SERVER['REDIRECT_URL'];
} else if (isset($_SERVER['REQUEST_URI'])) {
$file = $_SERVER['REQUEST_URI'];
}
$last_modified_time = filemtime($file);
$etag = md5_file($file);
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $last_modified_time) . ' GMT');
if (
strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) === $last_modified_time ||
trim($_SERVER['HTTP_IF_NONE_MATCH']) === $etag
) {
if (isset($_SERVER['SERVER_PROTOCOL'])) {
header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');
} else {
header('HTTP/1.0 304 Not Modified');
}
}
The script checks for changes to the file and if it does not, then it sends the 304 code to the client response.
My question is the following, is it possible to do this without using PHP, ie using only .htaccess
?