Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I read the local IP address into an .htaccess file?

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?

like image 496
Jay Blanchard Avatar asked Mar 14 '23 17:03

Jay Blanchard


1 Answers

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
like image 142
Amit Verma Avatar answered Apr 06 '23 07:04

Amit Verma