Apache httpd: Conditionally set response header based on another * response * header

Is there a way to set a new response header conditionally, where the condition uses a different response header? In particular, a new response header should only be set if the response has a specific Content-Type.

I looked at mod_headers in combination with mod_setenvif , but it looks like conditions can only use request headers, not response headers.

Thanks, John

+7
apache apache2
source share
1 answer

Apache 2.4 is the answer:

Set Cache-Control header when response content type is application / pdf

Header set Cache-Control "no-store,no-transform" "expr=%{resp:Content-Type} =~ m|application/pdf|"

DO NOT try with the IF directive. He is evaluated too early in the process. For example, the following will NOT work:

<If "%{resp:Content-Type} =~ m|application/pdf|"> Header set Cache-Control "no-store, no-transform" </If>

+5
source

All Articles