I just moved some sites to a new host, that doesn't support mod_expires; not sure why, I contacted them about it. anyways, I like images to be as cached as it possible can, to reduce bandwidth and to increase the speed of the site. My 'normal' configuration would then be something like this: (.htaccess) But this host returns a 500 Internal Server Error a ExpiresActive is not understood. After some puzzling, I create this php file and .htaccess and want to share it with you. It does exactly the same as above, the difference is that the headers are 'faked' by PHP instead of the apache server (Which will be more efficient ofcourse; so ignore my piece if you can use mod_expires) file: expires.php <? $cachetime=(86400*7); $file = $_SERVER["DOCUMENT_ROOT"] . $_GET["file"]; if (!file_exists($file)) { Header("HTTP/1.1 404 Not Found"); Header("Content-Type: text/plain"); echo "404 not found, image not found..."; die(); } $ext = strtolower(strrpos($file, ".")); switch($ext) { case "gif": $mimetype= "image/gif"; break; case "pjpeg": case "jpeg": case "jpg": $mimetype= "image/jpeg"; break; case "png": $mimetype = "image/png"; break; case "ico": $mimetype = "image/x-icon"; break; default: $mimetype = "image/gif"; } header("Content-type: " . $mimetype); header("Cache-Control: max-age=".$cachetime); $t = filemtime($_SERVER["SCRIPT_FILENAME"]); header("Expires: " . date("r", time() + $cachetime)); header("Last-Modified: " . date("r", $t)); header("Content-Length: " . filesize($file)); $fp = fopen($file, "rb"); while ($fp && !feof($fp)) { $buf = fread($fp, 10000); echo $buf; } if ($fp) { fclose($fp); } die(); ?> PHP: file: .htaccess RewriteEngine On RewriteRule ^(.*)\.gif$ expires.php?file=/img/$1.gif [L] Code (markup): put both files in your /img/ directory. No warrenties - if it works for you, cool; if not, sorry.
Just to add, if you have no idea what mod_expires is: http://httpd.apache.org/docs/1.3/mod/mod_expires.html