Score:0

Apache: I cannot set full cache header for text/html using htaccess

ro flag
228

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".

Score:0
ro flag
228

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>
Score:0
cn flag
Bob

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)$">
228 avatar
ro flag
228
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.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.