Search code examples
apache.htaccesscache-control

".htaccess" doesn't work for cache-control at sub directories


I made my own cache-control rule in httpd.conf. ANd need to apply different rules on each different sub directories.

I made no-cache for .do extension for default(httpd.conf).

# use .htaccess files for overriding,
AccessFileName .htaccess

...


    <ifModule mod_headers.c>
      <LocationMatch "\.(do)$">
        Header append Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
      </LocationMatch>
    </ifModule>

And need to cache for some directories(.htaccess).

example URL : XXX.com/en/product.do

So I made a .htaccess on <webRoot>/en.

<ifModule mod_headers.c>
  <LocationMatch "\.(do)$">
    Header set Cache-Control "max-age=216000, public, must-revalidate"
  </LocationMatch>
</ifModule>

Am I going wrong? Is there other way to rule different on different directories?


Solution

  • Nothing like <locationMatch> can be used in .htaccess; it will generate a runtime error.

    Also, usually *.do is proxied, in which case no filesystem directory would ever be read for .htaccess.

    I suggest putting the second stanza first, and adding ^/en/ to the front.