How to prevent Apache from prepending REDIRECT_ to environment variables when running php as CGI?

I've been using MediaTemple's GridService as a production environment for a couple of relatively lightweight PHP sites. The process of setting up testing and staging environments is kind of cumbersome and leads to staff taking shortcuts, so I'm trying to put together a quality control environment that provides a similar environment to GridService but that allows me to hook it more closely to our automated deployment process (provisioning new environments in GridService requires you to use the web interface; mod_vhost_alias would just allow us to create directories that are subdomains of our test url).

I am very, very close, but encountered an issue - with PHP running as CGI, apache automatically prepends REDIRECT_ to any variables I set in .htaccess (remember, I'm simulating GridService) using SetEnv. For example:

.htaccess

SetEnv HTTP_TEST_VAR "Some Value"

PHP

echo getenv('HTTP_TEST_VAR'); // prints ""
echo getenv('REDIRECT_HTTP_TEST_VAR'); // prints "Some Value"

This wouldn't be a big deal (we could code around it), except that it doesn't happen in GridService, and I really would prefer to have identical code paths (adding switching logic to the code would defeat the point of all the work we've done to get configuration out of the codebase).

For the rest of the background, I'm using a brand new (2 weeks old) (ve) instance running Ubuntu, got apache and all dependencies from apt, and built PHP (5.3.15) using the configure string from a <?php phpinfo() ?> on GridService, minus db4 support.

I would really appreciate any help. Thanks!


Don't know will it be a good solution, but PHP running in FastCGI mode (mod_fastcgi) runs OK with SetEnv variables without prepending it with REDIRECT_.

Had the same issue with PHP running in CGI mode, solved by switching to FastCGI.


I don't think you can change this behaviour with php-cgi as in effect it is a redirect. Note though that the php getenv() function return value

Returns the value of the environment variable varname, or FALSE if the environment variable varname does not exist.

so you can easily construct a function that returns the value whether it's REDIRECT_ or not.