问题
I have the following rules in a htaccess file
RewriteEngine On
RewriteRule mytest.php test.php
RewriteCond %{QUERY_STRING} !done
RewriteRule (.*) $1?done [E=TEST:itworks]
The file test.php is simply
<?php
echo "TEST = " . getenv('TEST');
?>
When I enter the request uri test.php, the environment variable TEST is defined and it echoes 'Test = itworks'. However, when I enter the request uri mytest.php, it also goes to test.php, but the environment variable TEST is not defined and it echoes 'Test =' .
Is that the expected behavior? If it is a bug in my environment, never mind. Otherwise, perhaps one could use that simple case to explain to me how it works.
回答1:
When you go through mytest.php
, there is an additional round through mod_rewrite.
The environment variables are then prefixed with REDIRECT_
. If you check for REDIRECT_TEST
, you will see the desired output
<?php
echo "TEST = " . getenv('TEST') . "/" . getenv('REDIRECT_TEST');
See Available Variables for some details.
来源:https://stackoverflow.com/questions/16205194/how-the-environment-tag-e-works-in-htaccess-mod-rewrite