I am attempting to control the caching of files inside a certain directory. I would like the default cache time for you to be fifteen minutes, but I wish to allow the application change it out if required. For instance, I could have a PHP script that I wish to refresh every one minute, so I'll set the cache-control headers within PHP for your script. However for the many other files Among the finest the cache time for you to be fifteen minutes, plus some of individuals are static files, and so i can't just set a default cache-amount of time in PHP.

I presently have this during my Apache config:

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Header set Cache-Control "max-age=900"

This is effective for 99% from the cases, where Among the finest a 15 minute cache. However, if my PHP script sets a cache-control header, than the setting will overwrite it.

I have checked out the documentation for mod_header and no configurations (unset, add, append, etc.) appear to provide me things i need.

Thanks ahead of time.

Based on php manual

header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past

By delivering the headers above, you need to override any configurations that could otherwise make the creation of your script to become cached.

Have a look at mod_expires rather http://httpd.apache.org/docs/2.2/mod/mod_expires.html. The paperwork state that it will not overwrite headers produced because of your PHP script:

"Once the Expires header has already been area of the response produced by the server, for instance when produced with a CGI script or proxied from an origin server, this module doesn't change or add an Expires or Cache-Control header."

Here's a good example config for mod_expires:

 <IfModule mod_expires.c>
     ExpiresActive on
     ExpiresDefault A600
     ExpiresByType image/gif "access plus 1 day"
     ExpiresByType image/jpeg "access plus 1 day"
     ExpiresByType image/png "access plus 1 day"
     ExpiresByType image/x-icon "access plus 1 day"
     <FilesMatch "\.(php|php4)$">
         ExpiresByType text/html "now"

Obtained from http://howto.gumph.org/content/reduce-webserver-bandwidth/

Best of luck!