Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess if statement

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?

like image 708
geoffs3310 Avatar asked Dec 21 '12 14:12

geoffs3310


Video Answer


1 Answers

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>
like image 109
julp Avatar answered Sep 18 '22 12:09

julp