How the Environment tag E works in .htaccess mod rewrite

人走茶凉 提交于 2019-12-12 03:03:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!