.htaccess中的条件php_flag语句

i-g*_*i-g 6 php apache .htaccess

有没有办法在.htaccess中有条件地执行php_flag语句?以下是我要做的两件事:

如果客户端的IP地址与我使用的IP地址匹配,则打开错误报告:

if %{REMOTE_ADDR} == '12.34.56.78' then
   php_flag error_reporting 1
else
   php_flag error_reporting 0
Run Code Online (Sandbox Code Playgroud)

register_globals如果IP地址与我的匹配,则关闭,以便我可以调试由期望启用此代码的代码引起的任何问题.

if %{REMOTE_ADDR} == '12.34.56.78' then
   php_flag register_globals on
else
   php_flag register_globals on
Run Code Online (Sandbox Code Playgroud)

谢谢阅读!

MrW*_*ite 1

if %{REMOTE_ADDR} == '12.34.56.78' then
   php_flag error_reporting 1
else
   php_flag error_reporting 0
Run Code Online (Sandbox Code Playgroud)

只有在 Apache 2.4+ 中出现Apache 表达式时,这才真正成为可能,您可以在其中执行此类操作...

<If "%{REMOTE_ADDR} == '12.34.56.78'">
    php_flag error_reporting 1
</If>
<Else>
    php_flag error_reporting 0
</Else>
Run Code Online (Sandbox Code Playgroud)

如果在 Apache 2.2 上,这实际上是不可能的,特别是对于依赖于请求的东西,例如REMOTE_ADDR. 在 Apache 2.2 上,您有<IfDefine>,但这仅测试已使用该选项在 Appache 命令行上定义的参数-D是否存在。所以,这实际上是一个每服务器配置开关。(在 Apache 2.4 上,您可以使用Define服务器配置中的指令来有条件地定义参数,但是,这仍然无法根据请求的元素来定义,AFAIK。此外,无论如何,您都可以在 Apache 2.4 上使用 Apache 表达式。 )