Apache ForceType application/x-httpd-php and PHP CGI

To display “static” pages here I use the Apache “ForceType” directive so that all requests to /pages/something get processed by a php file called “pages”. Unfortunately that doesn’t work as easily when PHP is running as a CGI.
I found a possible solution in this Textpattern forum thread. Not sure if you can put “ScriptAlias” into a .htaccess file. I just checked and no, you can’t. That limits the usefulness of this solution dramatically!
Here’s how to use PATHINFO to create search engine friendly URLs. Again, it uses the ForceType idea.
Looks like it’s worth perceivering with mod_rewrite after all!


3 Comments

James Van Lommel (1 comments.) on December 10, 2004 at 10:47 pm.

I’ve been playing with Textpattern and encountered the problem you were describing here. I came up with an .htaccess solution that seems to work pretty well:

AddHandler php-cgi .php
Action php-cgi /cgi-bin/php.cgi


ForceType php-cgi

The first two lines are because I rolled my own PHP CGI and installed it. (I’m not using Dreamhost’s CGI.) The next section is from the Textpattern sample .htaccess, but I modified it.

If I had left it to say “ForceType application/x-httpd-php” it would run PHP as a module, which isn’t what I want. If it says “Force Type application/cgi-bin” it runs it as the default CGI. Still not good. On a hunch, I changed it to “ForceType cgi-bin”, and that worked.

It seems the ScriptAlias command isn’t necessary to get it working after all. I now have SEF URL’s on my site running PHP as a CGI.

Reply

Donncha (1707 comments.) on December 10, 2004 at 11:34 pm.

Nice bit of work James, and useful. In the last 2 weeks WPMU (the software that runs this site) has gone through an extensive reworking of the mod_rewrite rules, with some pain I can tell you!
I think the rules are just about there now and give an added benefit. All “unknown” requests are sent through mod_rewrite now, so what I may do, right at the end of my mod_rewrite ruleset is have a catch-all rule that sends requests to my solitary “pages” script, or in other words, it does the same thing as the ForceType stuff but should be more portable I hope!

Reply

Leave Your Comment

Your email will not be published or shared. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Holy Shmoly! is Stephen Fry proof thanks to caching by WP Super Cache