I am planning to use a single .htaccess
file which may be deployed on multiple servers. In the process I am setting environment variables in the .htaccess
file and there are a couple of cases where I would like to read the IP address into the settings. For instance, in one case I am setting an environment variable for the local database connection:
SetEnv DBL "mysql:dbname=oars;host=192.168.101.1;port=3306"
Then in PHP I would read the variable for use by the database interactions:
define('DBL', getenv('DBL'));
Since I am planning to deploy on multiple servers is there a way to get the IP address automagically rather than maintaining separate .htaccess files for each server?
You can use a Rule to set the Env variable:
RewriteEngine on
RewriteRule ^ - [E=DBL:mysql\:dbname=oars\;host=%{SERVER_ADDR}\;port=3306]
print getenv("DBL");
mysql:dbname=oars;host=1.2.3.4.5;port=3306
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With