To the following browser caching via mod_expires.c in the .htaccess...
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 day"
</IfModule>
...I would like to add an exception: One or more folders shall not be cached. I tried a version with Directory before </IfModule>, but that led to a 500 Internal Server Error. That
<Directory "/absolute/path/to/specialfolder">
ExpiresActive On
ExpiresDefault "access plus 1 seconds"
</Directory>
and that snippet
<Directory "/absolute/path/to/specialfolder">
ExpiresActive Off
</Directory>
What's wrong and what could help? (for one or a few folders)
The
<Directory>directive is not permitted in a.htaccesscontext, it can only be used in a server (or virtualhost) context. (Hence the 500 error.)The userland/
.htaccessway would be to create another.htaccessfile in that "specialfolder" withExpiresActive Offin order to override the parent config.Alternatively, you could perhaps use an
<If>expression in the root.htaccessfile.For example:
Where
REQUEST_URIis the document-root-relative URL-path.OR, only use mod_expires when not requesting these folder(s). For example:
Although disabling mod_expires does not necessarily prevent the resource from being cached. It simply prevents mod_expires from setting the
Cache-Control(andExpires) headers. If you specifically want to disable caching then consider explicitly setting the relevantCache-Control/Expiresheader(s) directly.For example:
In this example, you do not need to disable mod_expires since the
Headerdirective will override mod_expires (since mod_headers is processed after mod_expires).