I have used this before;
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/gif "now plus 2 weeks"
// Lots omitted here
</IfModule>
And this;
<IfModule mod_headers.c>
<filesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|JPG)$">
Header set Cache-Control "max-age=1209600"
</filesMatch>
// Lots omitted here
</IfModule>
I can set the expires on by content-type and I can set any header I wish by file extension.
But neither of these seem to let you set any header you want by content-type.
I want to set the cache-control header based on the content-type of the response - note that this is not the same as the file extension. I have "friendly URLs" so there is no file extension to be captured by filesMatch
so there is no file extension but the content-type is text/html
.
How can I set the cache-control header for specific content-types?
In 2.4, you can append expr=
to the Header directive instead of env=
. For example:
Header set Cache-Control "max-age=3600" "expr=%{CONTENT_TYPE} == 'text/html'"
In the default (non-early) mode, mod_headers
runs as an output filter – so the content type is already set and available by the expression parser.
http://httpd.apache.org/docs/2.4/expr.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With