Set Content-Type Header

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 expire by type of content, and I can set any header I want with the file extension.

But none of them seem to allow you to set any title you want by content type.

I want to set the cache control header based on the type of response content - note that this is not the same as the file extension. I have "friendly URLs", so there is no file extension that filesMatch should filesMatch , so there is no file extension, but the content type is text/html .

How to set cache control header for certain types of content?

+7
content-type header apache apache2
source share
3 answers

In version 2.4, you can add expr= to the Header directive instead of env= . For example:

 Header set Cache-Control "max-age=3600" "expr=%{CONTENT_TYPE} == 'text/html'" 

In standard (not earlier) mode, mod_headers works as an output filter - therefore, the content type is already set and available to the expression analyzer.

http://httpd.apache.org/docs/2.4/expr.html

+7
source share

I think you will need to first add or set the Cache-Control header. Try the snippet below and don't forget the "no-transform" parameter.

 <IfModule mod_expires.c> ExpiresActive On ExpiresByType image/gif "now plus 2 weeks" // Lots omitted here //This is the magic <IfModule mod_headers.c> Header append Cache-Control "public, no-transform" </IfModule> </IfModule> 
-one
source share

If you want to create a cache content type, you can enter it as follows:

 <IfModule mod_expires.c> ExpiresActive on ExpiresByType text/html "access plus 15 days" </IfModule> 
-2
source share

All Articles