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>
Aly
  • 133
  • 8

1 Answers1

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"');
  }
  /* ... */
?>
danlefree
  • 2,923
  • 1
  • 19
  • 20