Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to configure a local apache server to serve php files with different php versions. In my document root I have phpinfo.php, now if I go to http://localhost/phpinfo.php4, I want to see the phpinfo.php file processed with php4, if I go to http://localhost/phpinfo.php5 I want to see the same file processed with php5.

Note: both php 4 and 5 are already installed side by side, I have no problem configuring apache to treat files that have a .php4 or .php5 extension on the filesystem with the correct php version. What I want is for apache to do the following:

  • If the url-path ends in .php5, serve the file which has a .php extension on the filesystem using the application/x-httpd-php5 handler.
  • If the url-path ends in .php4, serve the same file with the .php extension on the filesystem using the application/x-httpd-php4 handler.
share|improve this question
up vote 1 down vote accepted

After a bit of trial & error I figured it out. The magic incantations are

RewriteEngine on
RewriteRule ^(.*)\.php5$ $1.php [H=application/x-httpd-php,PT]
RewriteRule ^(.*)\.php4$ $1.php  [H=php4,PT]

where application/x-httpd-php is the default handler that mod_php5 registers, and php4 is a custom cgi handler that calls php4. The part I had most trouble figuring out is the PT (passthrough) flag, which is necessary for cgi handlers to work. PT causes other modules that do url rewriting to also do their job, and mod_cgi is such a module.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.