title: Conditionally setting cache headers in apache
body: <p>I want to conditionally set cache headers depending on what path files are accessed from. Basically, accessing <code>http://www.example.com/cache/$cache_key/*</code> should serve files with far in the future cache headers. </p>
  
  <p>I'm using a rewrite rule to set an environment variable and then attempting to set cache control headers based on that variable. However, it seems like the variable is being set too late in the process or something; the conditional header rules are never getting executed.</p>
  
  <pre><code>RewriteRule ^cache/.*?/(.*) /$1 [env=asset:true,L]
  Header set Cache-control "max-age=30"
  Header set Cache-Control "max-age=31536000" env=asset
  Header unset ETag env=asset
  </code></pre>
  
  <p>Is there a better way to do this? I've tried a couple of combinations of Directory and Location blocks with no success.</p>