【问题标题】:Conditional php_flag statements in .htaccess.htaccess 中的条件 php_flag 语句
【发布时间】:2010-02-13 17:55:50
【问题描述】:

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

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

if %{REMOTE_ADDR} == '12.34.56.78' then
   php_flag error_reporting 1
else
   php_flag error_reporting 0

如果 IP 地址与我的 IP 地址匹配,请关闭 register_globals,以便我可以调试由预期此打开的代码引起的任何问题。

if %{REMOTE_ADDR} == '12.34.56.78' then
   php_flag register_globals on
else
   php_flag register_globals on

感谢阅读!

【问题讨论】:

    标签: php apache .htaccess


    【解决方案1】:
    if %{REMOTE_ADDR} == '12.34.56.78' then
       php_flag error_reporting 1
    else
       php_flag error_reporting 0
    

    这只有在 Apache 2.4+ 中出现 Apache Expressions 时才真正成为可能,您可以在其中做这种事情...

    <If "%{REMOTE_ADDR} == '12.34.56.78'">
        php_flag error_reporting 1
    </If>
    <Else>
        php_flag error_reporting 0
    </Else>
    

    如果在 Apache 2.2 上这是不可能的,尤其是依赖于请求的东西,比如REMOTE_ADDR。在 Apache 2.2 上,您有 &lt;IfDefine&gt;,但这仅测试在 Appache 命令行中使用 -D 选项定义的 参数 是否存在。所以,这实际上是一个每个服务器的配置切换。 (在 Apache 2.4 上,您可以在服务器配置中使用 Define 指令有条件地定义参数,但是,这仍然不能基于请求 AFAIK 的元素来定义。此外,您有无论如何在 Apache 2.4 上使用 Apache 表达式。)

    【讨论】:

      猜你喜欢
      • 2012-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多