Forum Moderators: phranque

Message Too Old, No Replies

setting specific headers for some images

         

bb22

1:09 pm on Jan 29, 2004 (gmt 0)

10+ Year Member



Hello,
Ok here's what i want:
I have some set of images that can be remotely linked by other sites (let's call them "trackers"), and for which i would like to do log analysis in order to generate rough traffic statistics (basically, get a number of daily unique visitors). Stats will be performed by a cron parsing the server logs, no need for real time tracking, so people include the image directly using the image filename.

In order to do this i must be sure that anyone accessing the linking site sends a request to the image at least daily.
I understand that to do so i must use the "expires" http header, however i have no idea how to do this for an image that is accessed directly. Anyway i can do this by adding directives to httpd.conf?

What would be perfect would be to allow the browser to cache the image (if i can avoid it to be downloaded everytime it's only better), but to have it send an http request at least once a day (even if it is to get a 304-unmodified response, the point is to get an entry in my log).

Thanks for any help on how to achieve this.

jdMorgan

5:37 pm on Jan 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



bb22,

Welcome to WebmasterWorld [webmasterworld.com]!

I dealt with this problem several years ago, and never found a good example that included both the headers and the directives needed to implement them. So straight off one of my servers:


ExpiresActive On
# Default - Set http header to expire everything 2 weeks from last access, set must-revalidate
ExpiresDefault A604800
Header append Cache-Control: "must-revalidate"
#
# Apply a customized Cache-Control header to frequently-updated pages
<FilesMatch "^(index¦news)\.html$">
ExpiresDefault A2400
Header unset Cache-Control:
Header append Cache-Control: "no-cache, must-revalidate"
# Apply a customized Cache-control header to tracker gifs
</FilesMatch>
#
# Apply a customized Cache-Control header to custom error pages
<FilesMatch "^(403¦404¦410)\.html$">
ExpiresDefault A0
Header unset Cache-Control:
Header append Cache-Control: "no-cache, must-revalidate"
</FilesMatch>
#
# Apply a customized Cache-control header to tracker gifs
<FilesMatch "tracker\.gif)$">
ExpiresDefault A0
Header unset Cache-Control:
Header append Cache-Control: "no-cache, must-revalidate"
</FilesMatch>

Technically, the Header unset directive should not be needed, but I found one server where the code didn't work without it -- Header set by itself was not working properly for some reason, so I had to use Header unset followed by Header append instead. You could try it using Header set, though; It might work on your server(s).

Note that the broken pipe "¦" character in the code above must be replaced with a solid pipe character from your keyboard before use -- Posting on this board modifies the the original solid pipe character.

Ref:
http://www.mnot.net/cache_docs/
http://webmaster.info.aol.com/caching.html

Tools:
http://www.ircache.net/cgi-bin/cacheability.py?
[webmasterworld.com...]

Jim

bb22

6:04 pm on Jan 29, 2004 (gmt 0)

10+ Year Member



wow, now that's the hell of an answer.

one word: thanks!

bb22

6:22 pm on Jan 29, 2004 (gmt 0)

10+ Year Member



from what i read on one of your links, i just want to make one thing sure:
setting the no-cache header will not prevent the tracker from being cached by the browser, but will force it to request the image every time, and it will keep serving the cached version if it gets a 304, am i right?

thanks again

jdMorgan

5:43 am on Jan 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, but you must also use must-revalidate if you want the client to abide by your "expires" header - which you explicitly stated was a requirement for your "Web beacon" image use.

Jim