ExpiresByType not working but <FilesMatch> IS in .htaccess?

1.4k Views Asked by At

I've been rather perplexed by this and was hoping someone might be able to shed some light.

In my htaccess file, I have:

<IfModule mod_expires.c>
  ExpiresActive on
  ExpiresByType text/html  "access plus 4 hours"
</IfModule>

However, it doesnt seem to be working when I check the headers.
I get "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"

But if I use THIS code:

# 4 HOURS
<FilesMatch "\.(html|htm)$">
Header set Cache-Control "max-age=14400, must-revalidate"
</FilesMatch>

It DOES pick up the cache. max-age=14400, must-revalidate

Am I missing something? Is one for the server and one for the browser? I mean, I'd prefer to use the first since it came with boilerplate if they are both the same.

Thanks in advance!

1

There are 1 best solutions below

0
On

I don't know if you already have the solution but are you sure mod_expire is enabled on your server? On ubuntu sudo apache2ctl -M.

You can also try to comment out <IfModule mod_expires.c> and </IfModule> and restart apache. It will crash if mod_expires is not enabled.

To enable mod_expire:

sudo a2enmod expires

mod_expires will create the Expire header and should modify the max-age=14400 part of the Cache-Control header only. For the must-revalidate part you will have to use Header.