Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

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

share|improve this answer
    
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)?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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