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 thoughts on “Apache ForceType application/x-httpd-php and PHP CGI

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

  2. 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!

Leave a Reply

%d bloggers like this:

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.