Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I can't find a way to do it. Is it even possible?

share|improve this question

migrated from Aug 25 '09 at 19:11

This question came from our site for professional and enthusiast programmers.

You could create a custom script and redirect all your images to that script. It's kind of a big overhead but it works if it's your only option.

For example

And that script would contain for example:

header('Expires: full_date_comes_here');

echo file_get_contents('images/'.$_GET['image']);

Note!!! This is just a dummy example and you should add validation to your script, to prevent attacks using "../" parts etc.

share|improve this answer

Yes, mod_expires will work via .htaccess files. Put this in your .htaccess file:

  ExpiresActive on
  ExpiresByType image/gif "access plus 1 day"
  ExpiresByType image/jpeg "access plus 1 day"
  ExpiresByType image/png "access plus 1 day"
share|improve this answer
mod_expires does not work in a shared hosting environment. I just tried this and got a 500 error. – Jared Jun 12 '10 at 0:28

Like this:

<FilesMatch "\.(jpg|png|gif|js|css|ico|swf)$">
    Header set Expires "Thu, 31 Dec 2037 23:55:55 GMT"
    Header set Cache-Control "public,max-age=315360000"
    Header set Vary "Accept-Encoding"

If you want a shorter caching period, remove Header set Expires and adjust Header set Cache-Control.

share|improve this answer

Windows based hosting with godaddy doesnt support .htaccess, you have to use web.config.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.