I have the following line in my .htaccess
file to select which version of PHP to use:
AddType x-httpd-php53 .php
This works great
Another alternative you can do is to change httpd.conf in the test environment to use ".htaccess-test" instead of ".htaccess".
This is simply done by modifying httpd.conf and adding the following line outside of any block:
AccessFileName .htaccess-test
NOTE: You can add AccessFileName inside a <VirtualHost> block if you want to apply it to a specific VirtualHost.
What this means is that the test environment will use .htaccess-test while the production environment will use .htaccess. Hence, you get the freedom of configuring each environment separately.
Then create a file named .htaccess-test adjacent to .htaccess. Modify .htaccess-test with your test configuration, then finally restart Apache Web server in the test environment server.
With Apache 2.4, it is easy with <If>
/<Else>
directives (on %{HTTP_HOST}
?).
<If "%{HTTP_HOST} == 'foo'">
# configuration for foo
</If>
<Else>
# default configuration
</Else>
For Apache 2.2 and earlier, I would add a parameter to the startup command line of Apache (-D
option) in one of the two environments then test if it is present or not via <IfDefine>
.
To do this on Windows, with Apache started as a service, modify key registry HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Apache2.<VERSION>\ImagePath
by appending -DFOO
. Then, you can write:
<IfDefine FOO>
# configuration for foo
</IfDefine>
<IfDefine !FOO>
# default configuration
</IfDefine>