开发者

Using Apache Server-side Flow Control in PHP?

开发者 https://www.devze.com 2023-01-14 14:21 出处:网络
As discussed a b开发者_运维百科it 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 par

As discussed a b开发者_运维百科it 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.


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.


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

A brief comment about what not to do. You'll occasionally see people recommending that you just tell Apache to parse all .html files for SSI, so that you don't have to mess with .shtml file names. These folks have perhaps not heard about XBitHack. The thing to keep in mind is that, by doing this, you're requiring that Apache read through every single file that it sends out to clients, even if they don't contain any SSI directives. This can slow things down quite a bit, and is not a good idea.

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?

http://httpd.apache.org/docs/2.2/mod/mod_include.html#xbithack

/Philip

0

精彩评论

暂无评论...
验证码 换一张
取 消