【问题标题】:cache only one image (.png) with ".htaccess" and not all images(.png)?只缓存一张带有“.htaccess”的图像(.png)而不是所有图像(.png)?
【发布时间】:2014-05-18 15:00:49
【问题描述】:

嘿, 我在我的 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 和 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>

但如果我使用“page speed test Google”或“pingdom tool”,不会导致图像 small.png 被缓存 错误在哪里?也许我需要插入图片的网址???

【问题讨论】:

  • 询问没有任何意义:/

标签: apache .htaccess caching drupal-7


【解决方案1】:

是的,您可以使用 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> 

【讨论】:

  • 所以,如果我的图片是“sm.png”,我需要这样写:
  • 您的评论是否不完整?
  • 我需要写这个吗? : ## EXPIRES CACHING ## ExpiresByType image/png "access 1 year" ## EXPIRES CACHING ##
  • 是的,这是正确的,但最好发布有问题的代码而不是评论。
  • 我不能使用“回答你的问题”,所以现在我编辑第一个问题;)
【解决方案2】:

是的,但我尝试过这种方式:

1)

     <FilesMatch '(image|sm)\.png$'>
      ExpiresByType image/png "access 1 year" 
     </FilesMatch>

但没有功能

      <FilesMatch "^(sm)\.png$">
        ExpiresByType image/png "access plus 1 year" 
      </FilesMatch>

没有作用

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-23
    • 2011-11-18
    • 2016-07-26
    相关资源
    最近更新 更多