Forum Moderators: phranque

Message Too Old, No Replies

Cache in htaccess

How to set headers in htaccess

         

anjanesh

8:07 am on Jan 4, 2008 (gmt 0)

10+ Year Member



To prevent caching via PHP
header("Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0");

How do I get the same thing done via htaccess?

ExpiresByType image/jpg "modification plus 0 hours 0 minutes"

Whats the difference b/w mod_expires & mod_headers?

jdMorgan

2:51 pm on Jan 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In .htaccess:

Header set Cache-Control: "no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0"

You can enclose this in a <FilesMatch> container if you wish to control cache on a per-filetype basis. With cache header values such as these --which disable caching-- it would be a good idea to do so; Otherwise, even static objects like images on your site will be uncacheable, and your server bandwidth will probably skyrocket.

Using the "Expires" directive modifies the max-age parameter in the Cache-Control header sent by the server. However, due to module execution order it may or may not be possible for mod_expires to override the max-age in the "Header set" line above.

Jim