How can I read the local IP address in a .htaccess file?

I plan to use a single .htaccess file that can be deployed on multiple servers. In the process, I set the environment variables in the .htaccess file, and there are several cases where I would like to read the IP address in the settings. For example, in one case, I set an environment variable to connect to a local database:

 SetEnv DBL "mysql:dbname=oars;host=192.168.101.1;port=3306" 

Then in PHP I would read a variable to use interaction with the database:

 define('DBL', getenv('DBL')); 

Since I plan to deploy on multiple servers, is there a way to get the IP address automatically and not support separate .htaccess files for each server?

+6
source share
1 answer

You can use the 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 
+7
source

All Articles