开发者

How to give different expires header for files in different folders with one .htaccess in root ?

开发者 https://www.devze.com 2022-12-27 18:03 出处:网络
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 wit

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号