Take the 2-minute tour ×

As discussed a bit in this question, I am using Apache mod_include with conditional flow control statements to alter the behavior of included shtml files depending on the URL of the parent page. The problem I'm having is that some of the pages on the site are PHP pages, which seems to mean that the mod_include directives are ignored (and instead treated as standard html comments).

Is there any way to have PHP pages correctly process these mod_include directives?

Specifically, here is what I am trying to have processed:

<!--#if expr='"$DOCUMENT_NAME" = /(podcasts\.php)|(series\.php)/' -->
<li id="features" class="current">
<!--#else -->
<li id="features">
<!--#endif -->

Similar lines blocks work in the .shtml files on the site, but for the php pages, all of the above ends up output to the client.

Edit: The closest thing to a solution I have come up with is to mimic the functionality of the included shtml file in a php file. I don't like this solution because it means that adding links in the future will require adding them to multiple places.

share|improve this question
Do you have problems with <!--#include virtual="foo.php" --> not being executed or .php files not being handled by mod_include? –  VolkerK Aug 30 '10 at 1:03
The former. Not specifically with <!--#include --> in this case, but rather <!--#if expr='"$DOCUMENT_NAME" = /(mypage\.php)/--> –  Jeffrey Blake Aug 30 '10 at 2:01
Question edited to provide more detail. –  Jeffrey Blake Aug 30 '10 at 2:04
If you are worried about having to add links in multiple places in the future if you chose the closest solution you have in mind, why not using some storage/retrieval mechanism, let it be a db, a folder with files, an array, and a function that would fetch and echo the markup chunk when required, this way you only change the referenced markup once and it gets included, or didn't I get the question right? –  aularon Sep 1 '10 at 17:29
The problem with this is the fact that much of the site is static .shtml files. Apache can handle the SSI to load one shtml file into another. To my knowledge there is no way (short of some ugly AJAX hack) to load a dynamic, database-driven function into a static shtml file. Am I wrong? –  Jeffrey Blake Sep 1 '10 at 20:12

2 Answers 2

up vote 1 down vote accepted

Assuming you're running PHP via mod_php (may not even matter) just adding:

AddOutputFilter INCLUDES .shtml .php

and it works fine for both .shtml and .php with both being properly parsed.

share|improve this answer
Yes! Adding this to my .htaccess file resulted in all pages behaving as desired. Excellent! –  Jeffrey Blake Sep 2 '10 at 22:53

I have just started to read about SSI but found this quote at http://httpd.apache.org/docs/2.2/howto/ssi.html#configuring


So if I understand it right, you should not include .php in AddOutputFilter since if forces Apache to search all .php pages for SSI directives since it will slow down the server.

Maybe there is another solution to your problem?



share|improve this answer

Your Answer


