如何根据查询字符串中的匹配项使用SetEnvIf? [英] How can I use SetEnvIf based on matches in the query string?

查看:65
本文介绍了如何根据查询字符串中的匹配项使用SetEnvIf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的网址是 example.com/subdir/index.php?foo=bar

index.php包含以下内容:<?php echo getenv( testenvvar); ?>

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

我正在.htaccess中设置环境变量,如下所示:

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

SetEnvIf Request_URI(索引)TestEnv =已工作

这将显示已工作。

如果我将其更改为 SetEnvIf Request_URI(bar)TestEnv = Worked ,则不会。

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

我该怎么做?

推荐答案

要匹配查询字符串,您将需要 mod_rewrite 规则,而不是 mod_setenv

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

将此代码放在root .htaccess中:

Place this code in root .htaccess:

RewriteEngine On

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

这篇关于如何根据查询字符串中的匹配项使用SetEnvIf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆