On WordPress, I would like to set the browser cache expiration on the “index.html” homepage to “0“.
And the rest of the html files in 1 week.
I tried to do it via htaccess using the code below
<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On
# Default directive
ExpiresDefault "access plus 1 month"
ExpiresByType text/html "access plus 1 week"
<FilesMatch "^(index.html)$">
ExpiresActive On
ExpiresByType text/html "access plus 0 seconds"
Header append Cache-Control "public"
</FilesMatch>
</IfModule>
But only a week’s setup works:
ExpiresByType text/html "access plus 1 week"
This setting inside “FilesMatch” is completely ignored.
ExpiresByType text/html "access plus 0 seconds"
However, when I try to disable the caching of the styles.css file instead of index.html, the code works.
It seems to be something related to the html type when it is inside “FilesMatch”
Can anyone help me with this, please?
2
Answers
if you are using WPRocket plugin for cache handling then it provide option to set value in particular page also
WordPress doesn’t use
index.html
. It usesindex.php
You can change your match like this:[a-z0-9]+)?
matches any extension on the index file?
makes the index file optional so that the rule might match the home page when the index file is implied rather than present in the URL.