![](/img/trans.png)
[英].htaccess cache-control doesn't cache my files (js|png|css etc.)
[英]cache only one image (.png) with “.htaccess” and not all images(.png)?
嗨,我在drupal網站的首頁中有一個要緩存的圖像,但是如果將其寫在htaccess中:
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresByType image/png "access 1 year"
</IfModule>
## EXPIRES CACHING ##
它將緩存所有文件(.png)...
我只想緩存一個image.png; 所以我問你有沒有辦法在“ .htaccess”中只緩存一個帶有規則的元素? 有可能嗎?
謝謝 :))
來自意大利的再見;)
編輯:
也可以寫:
## EXPIRES CACHING ##
<IfModule mod_expires.c>
<FilesMatch 'image\.png$ sites/all/themess/mysubtheme/images/sm.png'>
ExpiresByType image/png "access 1 year"
</FilesMatch>
</IfModule>
## EXPIRES CACHING ##
???
最后,如果我有兩張圖片(.png)(是sm.png e small.png),我會這樣寫:
## EXPIRES CACHING ##
<IfModule mod_expires.c>
<FilesMatch 'image\.png$ sites/all/themess/mysubtheme/images/sm.png'>
ExpiresByType image/png "access 1 year"
</FilesMatch>
<FilesMatch 'image\.png$ sites/all/themess/mysubtheme/images/small.png'>
ExpiresByType image/png "access 1 year"
</FilesMatch>
</IfModule>
## EXPIRES CACHING ##
2°編輯 :
我寫這個:
<FilesMatch '(image|small)\.png$'>
ExpiresByType image/png "access 1 year"
</FilesMatch>
但是,如果我使用“頁面速度測試Google”或“ pingdom工具”,則不會導致圖像small.png被緩存了錯誤在哪里? 也許我需要插入圖片的網址???
是的,對於某些高速緩存行為,您可以使用FilesMatch
指令來匹配和定位一個文件或一組匹配文件:
<FilesMatch 'image\.png$'>
ExpiresByType image/png "access 1 year"
</FilesMatch>
編輯:根據您編輯的問題,您可以使用:
<IfModule mod_expires.c>
<FilesMatch '(image|sm)\.png$'>
ExpiresByType image/png "access 1 year"
</FilesMatch>
</IfModule>
是的,但是我嘗試過這種方式:
1)
<FilesMatch '(image|sm)\.png$'>
ExpiresByType image/png "access 1 year"
</FilesMatch>
但不起作用
<FilesMatch "^(sm)\.png$">
ExpiresByType image/png "access plus 1 year"
</FilesMatch>
不起作用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.