fistameeny fistameeny - 3 months ago 14
Apache Configuration Question

Apache FilesMatch - matching a folder in the regular expression



I'm trying to cache some files using a .htaccess file for Apache2. I want to cache a particular folder longer than anything else, so i've been trying to use the FilesMatch directive like this:

<FilesMatch "skins(.*)\.(jpg|png|gif)">

ExpiresDefault A2592000

</FilesMatch>


I'm hoping to be able to cache all image files in the /skins/ directory and it's subdirectories. However, I can't quite get the regular expression to work - Apache just ignores it altogether.

How do you match a folder with
<FilesMatch>
in a .htaccess file?

Cheers,

Matt

Answer

FilesMatch should only match filenames so You could place the .htaccess file inside the "skins" directory and it should look something like,

<FilesMatch "\.(jpg|png|gif)">
ExpiresDefault A2592000
</FilesMatch>

or if in the httpd.conf file you could use,

<Directory path_to_the_skins_dir>
    <FilesMatch "\.(jpg|png|gif)">
    ExpiresDefault A2592000
    </FilesMatch>
</Directory>

good luck