Search code examples
apache.htaccesscakephpcakephp-2.0mod-expires

how to add header expire in cakephp 2


I am working on one of the cakephp2 website speed improvement.

now i need to setup some header expire and cache stuff.

but in cakephp in which htaccess I have to put my code.

And please suggest any nice htaccess codes.

I have tried

#Expire Header
<FilesMatch "\.(ico|jpg|jpeg|png|gif|js|css|swf)$">
ExpiresDefault "access plus 2 hours"
</FilesMatch>

but its not working, also I have tried couple of other code but none of them working for me.Is there any key configuration that am missing?

One more thing if is there any other tricks to improve performance then please suggest me.


Solution

  • add folowing code to .htaccess file

    # cache images/pdf docs for 10 days
    <FilesMatch "\.(ico|pdf|jpg|jpeg|png|gif)$">
      Header set Cache-Control "max-age=864000, public, must-revalidate"
      Header unset Last-Modified
    </FilesMatch>
    
    # cache html/htm/xml/txt diles for 2 days
    <FilesMatch "\.(html|htm|xml|txt|xsl)$">
      Header set Cache-Control "max-age=7200, must-revalidate"
    </FilesMatch>
    

    more information http://tutorialpedia.org/tutorials/Apache+enable+file+caching+with+htaccess.html