Forum Moderators: phranque
RewriteRule ^ - [E=foo:${HOME}] RewriteCond %{DOCUMENT_ROOT} (/home/\w+)/public_html
RewriteRule ^ - [E=foo:%1] RewriteRule ^ - [E=foo:${HOME}]
I could obviously still use $basepath = $_SERVER['HOME']; in PHP
$basepath = dirname($_SERVER['DOCUMENT_ROOT']);
I'm guessing that this variable is set by PHP instead of Apache, so it's not accessible pre-PHP?afaik, nothing ever happens in php until the server itself has done all its stuff and the request arrives at the page containing the php. (Or the invisible script, in the case of something like auto-indexing.)
but I'm not in love with the idea of using a condition without a fallback:: detour to horse's mouth [httpd.apache.org] because I'm so used to thinking of DOCUMENT_ROOT as an URL element, not a filepath ::
foreach ($_SERVER as $key => $val)
if (lcfirst($key) === $key)
$$key = (!empty($val)) ?
str_replace('%2C', ',', $val) :
false; What does “fallback” mean in this context? If the Condition isn't met--say, you changed some part of your root directory's filepath and forgot to update the RewriteRule--then the variable simply isn't set. Seems like that's what you would want in that case.
I discovered a few months ago that setting variables in my Apache configuration processed considerably faster than setting them in PHP
(Note, it was marginally faster to just set all of the server variables and leave off the if (lcfirst($key) === $key) condition, but I didn't like having that many unused variables floating around....
Are you talking about just setting ordinary variables in PHP (which is what you seem to be)? OR are you specifically setting "environment variables" in PHP, eg. with putenv()?
If you are doing the former (ie. these variables are only used by PHP), then setting env vars in Apache cannot be faster; since you are essentially doing twice the work?