Simone Nigro Simone Nigro - 6 months ago 126
PHP Question

Apache htaccess SetEnv: how concatenate environment variable in htaccess?

I want set some environment variable like this, eg.:

SetEnv SpecialPath "%{DOCUMENT_ROOT}/dir/"


but if i print
SpecialPath
in path PHP, eg.:

$_SERVER['SpecialPath'];


the output is

%{DOCUMENT_ROOT}/dir/


the expected output is:

/var/www/dir/


the question is: how concatenate environment variable in htaccess?

env_module is enabled

Answer

%{DOCUMENT_ROOT} variable is part of mod-rewrite so You can set env for a document root using SETenv directive, try this mod-rewrite based example :

RewriteEngine on


RewriteRule ^ - [E=SpecialPath:%{DOCUMENT_ROOT}/dir/,L]