Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
August 22, 2014, 03:40:48 PM

Pages: [1]   Go Down
  Print  
Author Topic: caching all images in a directory  (Read 1109 times)
gavine
Newbie
*
Offline Offline

Posts: 2


« on: September 17, 2007, 04:25:30 PM »

Hi all,

I'm having trouble getting my site to instruct browsers and intermediary servers to cache all images in certain directories for some time. I tried using the directive shown below in .htaccess files in the directories in question but this caused all images stopped loading altogether. I fired up my packet sniffer and it appears the server is returning a 500 Internal Server Error in reply to the image requests.

Can anyone help explain to me why this isn't working? Or know of a better way to achieve caching of all images in a directory? (I would hate to have to serve every image via .php code though).

# cache 1 month
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=2419200, public"
</FilesMatch>

Thanks very much,
Gavin
Logged
gavine
Newbie
*
Offline Offline

Posts: 2


« Reply #1 on: September 21, 2007, 12:02:48 AM »

I got this sorted out myself. Here is a way to do it if anyone ever needs to know.

Put these lines in the directories .htaccess file...

ExpiresActive On
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpg A2592000

The '2592000' bit is the number of seconds in 3 days. If you want caching for a different amount of time - use a different value.
And you can add extra lines for each image types.

Gavin
Logged
Pages: [1]   Go Up
  Print  
 
Jump to: