简体   繁体   中英

Getting environment variable in mod_headers from mod_rewrite

I'm trying to send a header based on an environment variable and according to the documentation I'm supposed to use the env condition.

However it is not working. This is my server configuration:

RewriteRule ([^\[]+)(?:\[immutable\].)js$ $1.js [NC,QSA,L,E=immutable]

Header set Cache-Control "immutable, no-transform, public, max-age=31536000" env=immutable

I have verified that if I remove env=immutable , the header sends for all responses.

The expected result is:

  • foo.immutable.js should serve foo.js with the Cache-Control header
  • foo.js should also serve foo.js but without the Cache-Control header

Any ideas as to why it is not working or if there's a way to dump out the environment in the ssl_access_log to debug?

Try checking against that REDIRECT_immutable

Since you actually make a substitution, and your Rewrite appears to be in per-directory context, an internal redirect occurs. So your envvar becomes renamed to REDIRECT_immutable by the time mod_headers is actually running on the internal redirect for the final URL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM