How can I use SetEnvIf based on matches in the query string?

本秂侑毒 提交于 2020-01-24 16:17:20

问题


The URL I'm using is, let's say, example.com/subdir/index.php?foo=bar

index.php contains this: <?php echo getenv("testenvvar"); ?>

I'm setting an enviroment variable in .htaccess like so:

SetEnvIf Request_URI (index) TestEnv=Worked

This prints "Worked".

If I change it to SetEnvIf Request_URI (bar) TestEnv=Worked, it does not.

How can I do this?


回答1:


To match query string you will need mod_rewrite rules instead of mod_setenv.

Place this code in root .htaccess:

RewriteEngine On

RewriteCond %{QUERY_STRING} bar [NC]
RewriteRule ^ - [E=TestEnv:Worked]


来源:https://stackoverflow.com/questions/31342631/how-can-i-use-setenvif-based-on-matches-in-the-query-string

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