6

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?

2
  • 1
    Is it mod_cache or mod_expires that you are using?
    – Weboide
    Jul 5, 2010 at 14:55
  • well i'm not using either currently, but there appears to be some default caching going on on the browser end.
    – brad
    Jul 5, 2010 at 16:23

2 Answers 2

11
<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.

1
  • amazing thx....
    – brad
    Jul 6, 2010 at 18:42
11

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>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .