Is there a way to conditionally execute php_flag statements in .htaccess? Here are two things I'm trying to do:
Turn error reporting on if the client's IP address matches the IP address I use:
if %{REMOTE_ADDR} == '12.34.56.78' then
php_flag error_reporting 1
else
php_flag error_reporting 0
Turn off register_globals
if the IP address matches mine, so that I can debug any issues caused by the code expecting this turned on.
if %{REMOTE_ADDR} == '12.34.56.78' then
php_flag register_globals on
else
php_flag register_globals on
Thanks for reading!
if %{REMOTE_ADDR} == '12.34.56.78' then php_flag error_reporting 1 else php_flag error_reporting 0
This is only really possible with the advent of Apache Expressions in Apache 2.4+, where you can do just this sort of thing...
<If "%{REMOTE_ADDR} == '12.34.56.78'">
php_flag error_reporting 1
</If>
<Else>
php_flag error_reporting 0
</Else>
If on Apache 2.2 this is not really possible, especially with something that is dependent on the request, like the REMOTE_ADDR
. On Apache 2.2 you have <IfDefine>
, but this only tests the existence of parameters that have been defined on the Appache command line with the -D
option. So, this is really a per-server configuration switch. (On Apache 2.4 you can use the Define
directive in the server config to define parameters somewhat conditionally, however, this still can't be defined based on elements of the request AFAIK. Besides, you have the use of Apache Expressions on Apache 2.4 anyway.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With