10

For an application based on Zend Framework I use apaches SetEnv in .htaccess. I use this on test, staging and production servers like so:

SetEnv APPLICATION_ENVIRONMENT production

On the staging server I couldn't read this env var in PHP. However when I did a var_dump( $_ENV ) in php I got the value but the key was prepended with REDIRECT_ becoming

REDIRECT_APPLICATION_ENVIRONMENT

Can anybody explain why this is happening, and how I can prevent this?

Decent Dabbler
  • 22,532
  • 8
  • 74
  • 106

2 Answers2

10

I'm guessing you have mod_rewrite rules in your .htaccess as well for Zend? I believe it may be mod_rewrite prepending that when it does a redirect so that the value won't be overridden by any new settings with the new URL.

nortron
  • 3,873
  • 1
  • 24
  • 27
  • You guessed correct indeed. You might be right about mod_rewrite, but I don't believe the other servers show this behaviour too, and they have the exact same mod_rewrite setup. I'll have to check it out. Thanks so far. – Decent Dabbler Feb 15 '10 at 19:05
  • 1
    @fireeyedboy I was actually surprised to find very little about this issue at all other than user comments in forum posts and no actual reliable source information. I did see one or two posts about it being Apache version specific, is your staging machine's Apache a different version than your dev and production? Are your dev and production the same and it's not doing it on either of those? – nortron Feb 15 '10 at 19:09
  • @fireeyedboy can you elaborate – did you do something to solve this? – Charlie Schliesser Oct 18 '12 at 17:54
  • 1
    @CharlieS I use the following to define the constant in my index.php file: `defined( 'APPLICATION_ENVIRONMENT' ) || define( 'APPLICATION_ENVIRONMENT', getenv( 'APPLICATION_ENVIRONMENT' ) ? getenv( 'APPLICATION_ENVIRONMENT' ) : ( getenv( 'REDIRECT_APPLICATION_ENVIRONMENT' ) ? getenv( 'REDIRECT_APPLICATION_ENVIRONMENT' ) : 'production' ) );` (defaulting to 'production' if it cannot find the environment variable) – Decent Dabbler Oct 18 '12 at 18:13
2

I had the same issue and it was because of was running PHP as cgi in my Apache.

After enabling mod_php, I could access to my variable without that prefix.

slashmili
  • 1,190
  • 13
  • 16