Myroslav Tedoski
Myroslav Tedoski

Reputation: 301

Exclude specific folder with images from being cached by Apache?

How can I exclude a specific folder that has a number of PNG images in it from being cached by Apache?

Here is my cache-control.conf

<IfModule mod_headers.c>

Header unset Pragma
Header unset ETag
FileETag None

<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=31536000, public"
</FilesMatch>

</IfModule>

EDIT: I should have clarified that for security reasons I have AllowOverride None in my httpd.conf for my virtual hosts.

Before I tried placing .htaccess file with the following content into the images folder but later realized that I had AllowOverride None set.

<filesMatch "\.(png)$">
    ExpiresDefault A0
    Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0"
    Header set Pragma "no-cache"
</filesMatch>

Is there any way to do this on a main Apache config level?

Thank you!

Upvotes: 1

Views: 1334

Answers (1)

Myroslav Tedoski
Myroslav Tedoski

Reputation: 301

I resolved this by turning On AllowOverride for that specific folder:

<Directory "/path_to_my_directory"> AllowOverride All </Directory>

in my VirtualHost, so my .htaccess file started to work only for that specifc folder.

Upvotes: 1

Related Questions