1

I am trying to set some environment variables inside my .htaccess file like so:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

SetEnv DB_NAME my_database
SetEnv DB_USER root
SetEnv DB_PASSWORD root
SetEnv DB_HOST 127.0.0.1

# END WordPress

However when I use any of those variables inside my php code they are prefixed with REQUEST_ for some odd reason, and this is only on my computer.

So for example $_SERVER['DB_NAME'] won't work but $_SERVER['REQUEST_DB_NAME'] will work fine.

Like I said this is only on my computer which is using MAMP PRO for running apache.

Any reason why this would be happening, it makes no sense to me as I didn't see any configs that would be causing this too

Brady Edgar
  • 486
  • 7
  • 27

1 Answers1

0

Not ideal but I had to fix the issue with a snippet to strip out REDIRECT_ if it existed. So now instead of doing $_SERVER['DB_USER']; I have to use getVar('DB_USER');

function getVar($key) {
   $prefix = "REDIRECT_";
   if(array_key_exists($key, $_SERVER))
   return $_SERVER[$key];
   foreach($_SERVER as $k=>$v) {
     if(substr($k, 0, strlen($prefix)) == $prefix) {
     if(substr($k, -(strlen($key))) == $key)
     return $v;
    }
  }

  return null;
}

If anyone found a solution to this without adding extra PHP code please let me know!

Brady Edgar
  • 486
  • 7
  • 27