简体   繁体   中英

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:

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

it will be cache all files (.png)...

I want cache only one image.png; so i ask you if there is a way cache only one element with a rule in the ".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:

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

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 ? 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 '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)

     <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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM