Forum Moderators: phranque

Message Too Old, No Replies

directory specific cache control

         

OnlyOne

5:47 am on Mar 8, 2015 (gmt 0)

10+ Year Member



I'm on shared hosting and don't have access to the configuration file, only the htaccess

I have numerous titles on my site and an images and thumbs folder for each. What I need to do is set the jpegs in the thumbs folder to expire in one year and the jpegs in the images folder to not be cached at all or the cache max-age set to zero. I need something like:

<filesMatch "*/images/.(jpg)$ >
Header Set Cache-Control "max-age=0, no-store"
</filesMatch>

unfortunately the above doesn't work because filesMatch will only match on file names and not path. I can't use the <directoryMatch> or <location> directives because they can't be used in htaccess files. A separate htaccess file in each images directory is impractical as there are many titles.

Is there another way to achieve this?

lucy24

6:06 am on Mar 8, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Is there another way to achieve this?

Boy, you've really gone through and shot down all possibilities haven't you.

If you need to set different directives for different directories, the only way is with multiple htaccess files. Maybe in some future Apache release it will be possible to nest <Directory> sections-- and hence to use <Directory> within htaccess-- but we're not there yet.

But you don't need <FilesMatch> envelopes unless you're setting different time periods for different files within the same directory. Just use a single line, like

ExpiresByType text/html "access plus 7 days"
or
ExpiresByType image/gif "access"

Your top-level htaccess may need an
ExpiresActive On
if it isn't already enabled.

:: detour to check something ::

The override category for "ExpiresActive" is Indexes (for most directives it ends up being FileInfo). That's good, because there is absolutely zero possibility that you'll be unable to use it. Well, unless your host has inexplicably not installed mod_expires at all, but let's not be ridiculous.

phranque

9:19 am on Mar 8, 2015 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



this is kind of a hack, but you could make your thumbs a different content type and use different cache control directives for each image type.