Htaccess filesMatch exclusion

.htaccessapache-2.2http-headersregex

I have the following directive in my htaccess

<filesMatch "\.(gif|jpe?g|png|js|css|swf|php|ico|txt|pdf|xml|html?)$">
    FileETag None
    <ifModule mod_headers.c>
        Header unset ETag
        Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
        Header set Pragma "no-cache"
        Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
    </ifModule>
</filesMatch>

I copied that regex from someplace in Web months ago. It should add those headers to any HTTP Response that does NOT have those extensions.

But it's not working, it's adding them to any Response.

I also need to create another directive to add Header set Cache-Control "max-age=3600, public" to Responses of files that DOES have them.

Could anybody help me make proper fileMatch regexes?

Best Answer

You've got a few capitalization errors in your config:

<filesMatch "\.(gif|jpe?g|png|js|css|swf|php|ico|txt|pdf|xml|html?)$">
 ^
 should be <FilesMatch ...

    <ifModule mod_headers.c>
     ^
     should be <IfModule...

    </ifModule>
      ^ 
      should be </IfModule>
</filesMatch>
  ^
  should be </FilesMatch>

Also, if you've got VirtualHosts, you need to make sure that you've got AllowOverride correctly configured