0

I had a similar problem where I couldn't set the full cache header for JS and CSS files in my htaccess file, and it turned out I couldn't because the cache expiry was being set on the server and I had to add AllowOverride all in the vhost container to get it working, but I still cannot set the full cache header for text/html on a page. I can set the max-age using mod_expires in my htaccess file, but if I try to set a cache header with this:

<FilesMatch "\.(html|htm|rtf|rtx|txt|xsd|xsl|xml|HTML|HTM|RTF|RTX|TXT|XSD|XSL|XML)$">
    FileETag MTime Size
    <IfModule mod_headers.c>
        Header set Pragma "public"
        Header set Cache-Control "no-cache, must-revalidate, public"
    </IfModule>
</FilesMatch>

The no-cache, must-revalidate, public doesn't show up. The only thing that shows in cache-control is the max-age. Does anyone know how to fix this so I can set the entire cache header in the htaccess for text/html?

Here is what I have after Bob's suggestion and it still doesn't work:

<FilesMatch ".+\.(html|htm|rtf|rtx|txt|xsd|xsl|xml|HTML|HTM|RTF|RTX|TXT|XSD|XSL|XML)$">
    FileETag MTime Size
    <IfModule mod_headers.c>
        Header set Pragma "public"
        Header set Cache-Control "no-cache, must-revalidate, public"
    </IfModule>
</FilesMatch>

I'm trying to set the cache header for the file that is called "/" in the DevTools > Network with initiator "document" and type "html".

228
  • 1
  • 1

2 Answers2

0

Your regex seems incorrect. At the moment it only matches files named .html , .htm etc. and not what you probably intended, all files with the .html extension.

Try:

<FilesMatch ".+\.(html|htm|rtf|rtx|txt|xsd|xsl|xml|HTML|HTM|RTF|RTX|TXT|XSD|XSL|XML)$">
Bob
  • 5,805
  • 7
  • 25
  • Still doesn't work. I'm trying to set the cache header for the file that is called "/" in the DevTools > Network with initiator "document" and type "html". Only the max-age will show in cache-control, which is set with mod_expires, and not the: no-cache, must-revalidate, public. – 228 Feb 22 '22 at 08:59
0

Here is how you do what I was trying to do. You don't actually specify a file type. It's confusing because you can set the max-age for this using the text/html type with mod_expires.

<IfModule mod_headers.c>
    Header set Cache-Control "max-age=31536000, no-cache, must-revalidate, public"
    Header set Pragma "no-cache"
</IfModule>
228
  • 1
  • 1