15

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 in the live environment but doesn't apply to the test environment and breaks the site.

Is there a way I can put it in an if statement or something by IP of the server or URL of website or something so that it only comes into effect in the live environment?

Simon East
  • 55,742
  • 17
  • 139
  • 133
geoffs3310
  • 5,599
  • 11
  • 51
  • 104
  • What's the difference between your live and test environments? How are they configured in Apache? And most importantly, how does it break? What's in the error_log? – Michael Berkowski Dec 21 '12 at 14:51

2 Answers2

31

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>
Simon East
  • 55,742
  • 17
  • 139
  • 133
julp
  • 3,860
  • 1
  • 22
  • 21
3

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.

Basil Musa
  • 8,198
  • 6
  • 64
  • 63