When setting environment variables using mod_rewrite rules within an .htaccess
file, you may encounter an issue where a REDIRECT_
prefix is added to the environment variable name. This occurs when the rewrite engine "starts over" or effectively "loops" within a directory context.
With each subsequent pass through the rewrite engine, any existing environment variables from the previous phase are prefixed with REDIRECT_
. This continues for every pass, resulting in variable names such as REDIRECT_REDIRECT_language
.
The exact reason and mechanism for this behavior depend on the directives specified in the .htaccess
file and any <Directory>
containers in the server configuration. Without examining your specific .htaccess
file, URLs, and expected responses, it is difficult to pinpoint the cause.
However, to potentially resolve this issue, you can try adding the L
(last) flag or END
(Apache 2.4) directive to your rewrite rule. This will prevent additional passes by the rewrite engine and the associated renaming of environment variables:
RewriteRule ^(en|de|fr|ar)/(.*) /$2 [E=language:$1,END]
Within PHP, you may be able to access the "top-level" variable using the following code:
<?php
$value = apache_getenv('language',true);