0

I am trying to set a cache control header when a browser requsets the following url:

www.example.com/php/getData.php?exampleField=exampleValue

As even though getData.php is a dynamic page, when the parameter exampleField equals exampleValue the response doesnt change. Therefore, there is no reason for the browser not to cache this result. My question is how do I write a FilesMatch rule in the .htaccess file to match this, I tried the following with no luck:

<FilesMatch "php/getData.php\?exampleField=(exampleValue1|exampleValue2)$">
Header set Cache-Control "max-age=3024000, must-revalidate"
</FilesMatch>

1 Answer 1

1

The GET parameters are not part of the filename, so <FilesMatch> will not match them.

Given that you are serving up a PHP file, have you considered simply adding the cache control header there?

<?php
  /* ... */
  if (
    @isset( $_GET['exampleField'] ) &&
    $_GET['exampleField'] == 'exampleValue'
  ) {
    header('Cache-Control "max-age=3024000, must-revalidate"');
  }
  /* ... */
?>
1
  • hmm I will give this a try tonight
    – Aly
    Mar 14, 2011 at 8:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .