简体   繁体   中英

How do I cache a file by it's name rather than extension using .htaccess

I'm creating an online shop and tutorial platform that allows people buy beauty products, pay for tuition and learn how to...you know...do makeovers on the site. I'm still designing the layout and behavior of the site, before I get to payment and sign-in options but when I tested the Home page with Google's Page Insights, they said something about leveraging browser caching. I want to cache some CSS, Javascript, jQuery and PHP scripts as well as social media icons, some of them are in ".png" format as well as the logo of the company. But there are many pictures with the ".png" extension subject to change on the site, but the logo may stay there for a year, there are also CSS files subject to change more often than others. All files I found on the internet teach me how to cache by file extension. I want to know how to be more specific and cache by name and extension using the Apache's .htaccess. Is that possible? If so, how do I do it?

You can restrict directives so they only apply to specific files using the <Files> directive

<Files "specific.png">
    # Your cache directives here
</Files>

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