问题
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