Search code examples
apache.htaccesscachingcache-control

.htaccess cache-control doesn't cache my files (js|png|css etc.)


As my title says, I am trying to cache-control the content on my website but it seems that my content isn't being cached.

This is my code in my .htaccess file:

Header unset Pragma
FileETag None
Header unset ETag

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

# cache html/htm/xml/txt diles for 2 hours
<FilesMatch "\.(html|htm|xml|txt|xsl)$">
Header set Cache-Control "max-age=7200, must-revalidate"
</FilesMatch>

I have tried a lot of tutorials but none of them seems to do the trick. By the way, other .htaccess codes, like redirecting and stuff, DOES work.


Solution

  • I figured it out, you gotta remove Header unset Last-Modified

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