简体   繁体   English

是否仅缓存一个带有“ .htaccess”的图片(.png),而不是全部图片(.png)?

[英]cache only one image (.png) with “.htaccess” and not all images(.png)?

Hy, I have in the home of my drupal site an image that i want cache, but if write this in the htaccess: 嗨,我在drupal网站的首页中有一个要缓存的图像,但是如果将其写在htaccess中:

  ## EXPIRES CACHING ##
  <IfModule mod_expires.c>
  ExpiresByType image/png "access 1 year"
  </IfModule>
  ## EXPIRES CACHING ##

it will be cache all files (.png)... 它将缓存所有文件(.png)...

I want cache only one image.png; 我只想缓存一个image.png; so i ask you if there is a way cache only one element with a rule in the ".htaccess" ???? 所以我问你有没有办法在“ .htaccess”中只缓存一个带有规则的元素? Is possible?? 有可能吗?

Thank you :)) 谢谢 :))

Bye from italy ;) 来自意大利的再见;)

EDIT : 编辑:

is possible write also: 也可以写:

 ## 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 ##

??? ???

and finally, if i have two images (.png) (are sm.png e small.png) i write this: 最后,如果我有两张图片(.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° EDIT : 2°编辑

i have write this: 我写这个:

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

but if i use "page speed test Google" or "pingdom tool", not result that the image small.png is cached Where is the error ? 但是,如果我使用“页面速度测试Google”或“ pingdom工具”,则不会导致图像small.png被缓存了错误在哪里? Maybe i need insert the image's url ??? 也许我需要插入图片的网址???

Yes you can use FilesMatch directive to match and target only one file or set of matching files for certain caching behavior: 是的,对于某些高速缓存行为,您可以使用FilesMatch指令来匹配和定位一个文件或一组匹配文件:

<FilesMatch 'image\.png$'>
  ExpiresByType image/png "access 1 year"
</FilesMatch>

EDIT: As per your edited question you can use: 编辑:根据您编辑的问题,您可以使用:

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

yes but i tried in this way : 是的,但是我尝试过这种方式:

1) 1)

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

but non function 但不起作用

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

not funcion 不起作用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 .htaccess cache-control不会缓存我的文件(js | png | css等) - .htaccess cache-control doesn't cache my files (js|png|css etc.) 在htaccess上为Webp更改png | jpeg - Change png|jpeg for webp on htaccess 如何在Apache2服务器上仅跟踪文件image.png - How to track only file image.png on Apache2 server htaccess:缓存所有图像,但从子文件夹中排除缓存图像 - htaccess: cache all images but exclude caching images from subfolder .htaccess重定向到文件夹中所有图像的占位符图像 - .htaccess redirect to placeholder image for all images in a folder 如何使用htaccess获取图像的文件名并重写路径以删除文件扩展名(jpg,png等)? - How to fetch the filename of an image and rewrite the path removing the file extension(jpg,png, etc.) using htaccess? .htaccess-如果扩展名为.png,则从URL中删除目录 - .htaccess - If extension is .png remove directory from URL htaccess-在多个子文件夹中将.php重写为.png - htaccess - rewrite .php to .png in multiple subfolders htaccess php到png的重写规则停止工作 - htaccess Rewrite Rule for php to png stopped working 如何在不重新压缩图像的情况下从png和jpg图像中删除元数据/ EXIF信息? - How do I remove metadata / EXIF information from png and jpg images without recompressing the image?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM