Apache no-cache on specific files

I have an application that has the following rewrite rule:

    RewriteCond /tmp/maintenance.html -f
    RewriteCond %{HTTP_HOST} !^backdoor.myapp.com$
    RewriteRule ^(.*)$ /tmp/maintenance.html [L] 

This is our 'maintenance mode'. so I enable maintenance by linking /tmp/maintenance.html with a real file (and keep backdoor access using backdoor.myapp.com).

Problem is, this page seems to be getting cached by browsers, so when maintenance is turned off, the user has to do a hard refresh in order to get back to the main app.

I'm wondering how I can set the headers for this particular file only in Apache2. I believe there's a no-cache header? I'm assuming I want to set that header for this file, and all should be good.

can someone direct me how to do that, or explain the mechanism by which this static file should never be cached in the user's browser?


<Directory /some/real/path/to/tmp>
  Header Set Pragma "no-cache"
  Header Set Expires "Thu, 1 Jan 1970 00:00:00 GMT"
  Header Set Cache-Control "max-age=0, no-store, no-cache, must-revalidate"
  Header Unset ETag
  FileETag None
</Directory>

That should do it for just about every browser out there.


To better control the granularity of the files being excluded from caching, you can use the "FilesMatch" directive.

Also, ensure that mod_headers and mod_rewrite are loaded on the server. If you are not sure, put the header directives in an "ifModule" section:

<FilesMatch "^(excludeme-1|excludeme-2)\.jar$">
    FileEtag None
    <ifModule mod_headers.c>
        Header Unset ETag
        Header Set Cache-Control "max-age=0, no-store, no-cache, must-revalidate"
        Header Set Pragma "no-cache"
        Header Set Expires "Thu, 1 Jan 1970 00:00:00 GMT"
    </ifModule>
</FilesMatch>