How to give different expires header for files in different folders with one .htaccess in root ?
I want to give different expiry headers to different images on my site. they are contained in different folders right now, what I want to do is give 开发者_如何学运维then different expires headers with one main .htaccess file. I know this can be done with multiple .htaccess files in those folders but I dont want it to be implemented that way, It will clearly be tough to manage.
Try using FilesMatch directive in your .htaccess file.
Eg:
# cache most product images at client side
ExpiresActive on
<FilesMatch "^images/products/[^\.]*\.(gif|jpe?g|png)$">
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
Header append Cache-Control "public"
</FilesMatch>
EDIT: This seems to be wrong! FilesMatch is said to match only files, so you cannot match directories as well. Sorry for bad post.
精彩评论