Forum Moderators: phranque

Message Too Old, No Replies

Apache and web browser cache

How to set apache?

         

dave741

1:26 pm on Jan 18, 2006 (gmt 0)

10+ Year Member



One silly question:

After reloding the page I can see a response 200 in my accesslog for all images from my website.

I want the pictures to by cached by the web browser, so, then I can see the 304 response in my log file.

How to set up properly the apache for this?

jdMorgan

5:13 pm on Jan 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's an example using mod_expires, mod_headers, and <FilesMatch>. See the Apache documentation for more info.

# Set up Cache Control and Expires headers
ExpiresActive On
# Default - Set http header to expire everything 1 week from last access, set must-revalidate
ExpiresDefault A604800
Header append Cache-Control: "must-revalidate"
#
# Apply a customized Cache-Control header to custom ErrorDocument files
<FilesMatch "^(40[134]¦410)\.html$">
ExpiresDefault A1
Header unset Cache-Control:
Header append Cache-Control: "no-cache, must-revalidate"
</FilesMatch>
#
# Set robots.txt at four hours
<FilesMatch "^robots\.txt">
ExpiresDefault A7200
</FilesMatch>

Change the broken pipe "¦" characters above to solid pipes before use; Posting on this board modifies them.

You could also use ExpiresByType if you only want to control certain filetypes like images.

Jim