Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
1  
Is it mod_cache or mod_expires that you are using? –  Weboide Jul 5 '10 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 '10 at 16:23

2 Answers 2

up vote 1 down vote accepted
<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.

share|improve this answer
    
amazing thx.... –  brad Jul 6 '10 at 18:42

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>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.