问题描述
我想知道有没有办法使用环境变量(或类似的)与if语句来打开或关闭某些事情,如display_errors,modpagespeed。
I was wondering if there's a way to use an Environment Variables (or similar) with an if statement in order to turn certain things on and off, such as display_errors, modpagespeed.
所以例如:
SetEnv DISPLAY_ERRORS on
<If "DISPLAY_ERRORS == on">
php_flag display_errors on
</If>
<If "DISPLAY_ERRORS == off">
php_flag display_errors off
</If>
我花了一段时间寻找这样的东西,但是我无法发现任何事情这个。这是可能的吗?
I've spent quite a while searching for such a thing but I was unable to uncover anything which does this. Is this even possible?
我正在寻找一种简单的方式来编辑htaccess使用PHP,但不是编写块到htaccess更容易,只需更改on和off值,也可以在我的应用程序中更容易地将其显示为单选按钮。
I'm looking for an easy way to edit the htaccess using PHP, but instead of writing blocks to htaccess it would be easier to just change the "on" and "off" values and would also make it easier to display this as radio buttons within my application.
推荐答案
可以试试写下来:
#SetEnvIf Request_URI "^" DISPLAY_ERRORS=off
SetEnv DISPLAY_ERRORS off
<If "-T env('DISPLAY_ERRORS')">
php_flag display_errors off
</If>
<Else>
php_flag display_errors on
</Else>
但是似乎< If>
在之前评估 SetEnv(If)
。
我想到的一个不同的工作方法是:
A different working approach I have in mind would be:
<IfDefine DISPLAY_ERRORS>
php_flag display_errors on
</IfDefine>
<IfDefine !DISPLAY_ERRORS>
php_flag display_errors off
</IfDefine>
并使用 -DDISPLAY_ERRORS
参数启动Apache要显示错误,或者对于Apache> = 2.4,请在虚拟主机配置中添加定义DISPLAY_ERRORS
。
And starting Apache with a -DDISPLAY_ERRORS
argument to display errors or, for Apache >= 2.4, add a Define DISPLAY_ERRORS
in the virtualhost configuration.
这篇关于使用环境变量与If语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!