Don Marti

Tue 04 Aug 2009 08:57:58 AM PDT

Apache config for an image-heavy site

Just working on my brother's web site (key, kids! Picture framing in Bloomington, Indiana!) and looking at some of the Apache config for dealing with images. Jeremy Zawodny explains "Expires:" headers, and Tom Sherman has some good advice on preventing hotlinking. So here's what I ended up with:

# put a long expires on the images
<Location /i>
  ExpiresActive On
  ExpiresDefault "access plus 360 days"

# disallow image hotlinking
RewriteEngine on
RewriteCond %{REQUEST_URI}  ^/i/
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(preview\.)?palimpsest-press\.com [NC]
RewriteRule (.*) / [R]

One more thing that I think is working well: I put the image preload JavaScript in the "onload" of the biggest image on the home page. So preloading starts only after the necessary images load.

Anyway, now it's now a JavaScript-heavy brochure site, but I'll break out the individual gallery pages as static pages eventually. Now I just have to keep an eye on this thing and SEO it. Time to break out Lisa Barone's helpful list again.