1

This config is close...

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

...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:

http://example.com/electronics/

would not be cached.

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

2 Answers 2

0

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)$"].

3
  • 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. Mar 4, 2010 at 6:31
  • Ah, my mistake. I overlooked the fact that you wanted to include the passed PHP variables as well.
    – Josh
    Mar 4, 2010 at 6:46
  • I tried the Location directive in .htaccess, but it was failing with a 500 error. I guess I need an example. Mar 4, 2010 at 16:30
0

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)?

You must log in to answer this question.

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