Php files with different extensions

i’m working on changing my site to use php5 cgi instead of php4 as an apache module. it’s going mostly fine, but i’m not sure of the best way to handle some php scripts that are not named *.php.

in one directory, i have a few files named *.png that contain php code that outputs png images. in another i have a *.rtf file that contains php code that outputs rtf. with php4 i just dropped a line like this into .htaccess for that directory:

AddType application/x-httpd-php .png

i came across this page in the wiki (, which says the php5 cgi executable is in /dh/cgi-system/php5.cgi and shows adding a handler to use the custom php.ini. from that it looks like i can do this:

AddHandler php-cgi .png
Action php-cgi /dh/cgi-system/php5.cgi

but it seems to me there should already be an Action defined that i could just use, which would mean i only need the AddHandler line (modified to use the right action of course).

another issue i’m going to have with this is that my local testing server doesn’t use cgi, and doesn’t have a /dh/ directory at all. is there a way i can specify that parts of .htaccess are for the live site on dreamhost and parts are for my test server? the domains, ports, and document roots are different between the two. i like to keep identical files on my test server and live server as much as possible, so i don’t make a change on the test server and then upload and break the live site!

edit: on second thought, it doesn’t look like /dh/ is accessible from .htaccess, since the example was talking about /cgi-bin/ which is under document root. so it looks like for now at least i have no way to use php5 for files not named *.php

after a lot of searching, i found the most important part of my answer at the very bottom of this page:,PHP&Databases/_PHP

I recently went through this procedure for a domain of mine. Try adding the following to your .htaccess file;

[color=#0000CC]AddHandler php-cgi .html .htm .php[/color]

Another issue that you might run into; After making the change, trying to access a non existent HTML page will not trigger a 404 error, instead you will see the PHP ‘no input file’ error. To fix this, simply add the following lines to your .htaccess file and create a custom 404.php file.

[color=#0000CC]RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /404.php [L][/color]


Save [color=#CC0000]$50[/color] on DreamHost plans using [color=#CC0000]PRICESLASH[/color] promo code (Click for DreamHost promo code details)