Conditionally setting cache headers in apache

后端 未结 1 640
说谎
说谎 2021-02-05 20:01

I want to conditionally set cache headers depending on what path files are accessed from. Basically, accessing http://www.example.com/cache/$cache_key/* should serv

1条回答
  •  难免孤独
    2021-02-05 20:48

    Using phpinfo() I determined the environment variable ends up not being set at all on the rewritten request, so the problem isn't the order of the request, it's that it seems to toss the variable out. Using the query string instead of the URL and not rewriting seemed to be the only way I could get this working. I do agree, it seems like there should be a better way.

    RewriteCond %{QUERY_STRING} longcache=true(&|$)
    RewriteRule .* - [ENV=LONGCACHE:true,L]
    
    Header set Cache-Control "max-age=30" env=!LONGCACHE
    Header set Cache-Control "max-age=31536000" env=LONGCACHE
    

    MORE DIFFERENT ANSWER OBTAINED BY OPENING EYES:

    Your asset environment variable gets renamed to REDIRECT_asset after the redirect, so your conditional Header directive needs to be:

    Header set Cache-Control "max-age=31536000" env=REDIRECT_asset
    

    0 讨论(0)
提交回复
热议问题