This config is close...

<FilesMatch "\.(php)$">
Header set Cache-Control "max-age=7200, must-revalidate"

...but it does all php pages, not just the home page like I want.

Basically the developer said he wants example.com to be cached, while:


would not be cached.

Note the developer is using pretty URLs with an MVC framework that runs everything through index.php.


The Apache FilesMatch directive accepts regular expressions, but that should also mean you can fit in the precise expression of just the filename [index.php] (which, from my understanding - which could be incorrect - is the only file you want to cache, even if it is using permalinks). Have you tried that?

Right now, you are finding all PHP pages using [".(php)$"].

  • Can't do index.php because in this case a PHP MVC framework funnels all requests to index.php. It's called "pretty URLs". So, what we need is a way to move beyond looking at files and looking only at URLs for doing the cache control, and do this from .htaccess if possible. – ServerChecker Mar 4 '10 at 6:31
  • Ah, my mistake. I overlooked the fact that you wanted to include the passed PHP variables as well. – Josh Mar 4 '10 at 6:46
  • I tried the Location directive in .htaccess, but it was failing with a 500 error. I guess I need an example. – ServerChecker Mar 4 '10 at 16:30

How about symlinking the php file to another name in the directory, say ln -s index.php cachedindex.php, having apache use cachedindex.php for / and set the cache header on that. Let the framework keep using index.php for all the other pages.

Although since you're working with the developer on this, is there a reason the php code isn't just outputting the appropriate cache header when the right options are set (in this case only when no options are set)?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.