Apache caching with mod_headers mod_expires

Solution 1:

You need to use the

ExpiresActive On

directive wherever you want to apply Expires headers, for example

<Location / >    
   ExpiresActive On
   ExpiresByType image/png "access plus 7 days"    
   ExpiresByType image/jpg "access plus 7 days"    
   ExpiresByType image/gif "access plus 7 days"

   ExpiresByType text/html "modification plus 5 days"

   <FilesMatch "\.(gif|jpe?g|png)$">        
      Header set Cache-Control "public"    
   </FilesMatch>

   <FilesMatch "\.(html)$">        
      Header set Cache-Control "public"    
   </FilesMatch>

   <FilesMatch "\.(php)$">
      Header set Cache-Control "private"    
   </FilesMatch> 
</Location>

Solution 2:

I know this is an old question but just in case anybody stumbles upon it...

There is a difference in using the FilesMatch and ExpiresByType directives.

FilesMatch matches a file by it's extension.

ExpiresByType matches a file by it's mime type.

It's generally better to use ExpiresByType.

Source http://www.websiteoptimization.com/secrets/advanced/caching-example.html