Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache HtAccess AddHandler Conditional on servername or ip

I'm hosting my staging and production servers at Site5, a relatively good hoster IMO. The question is not about their quality but more about an issue related to PHP's version.

Our development server is using PHP 5.3 which is a good version, 5.4 being too new, we don't want to use it's features yet, not enough widespread.

Problem is, Site5 uses PHP 5.2 by default but you can change to 5.3 using an HTACCESS AddHandler statement. Works fine on Site5 but our dev server crashes when we keep that statement in the HTAccess file.

If you use SVN/Git to deploy your web apps, you know that you always keep the same files everywhere, so thats where it hurts, i can't seem to find anything about conditional statements for HTACCESS files for AddHandler. I can write conditions on the rewrite engine easily, but i can't find anything that would look and act like this:

#<If SERVERNAME == "targethost.com">
#    PHP 5.3 configuration for site5
#    AddHandler application/x-httpd-php53 .php
#</If>

Anyone has a solution?

like image 686
Mathieu Dumoulin Avatar asked Sep 02 '25 17:09

Mathieu Dumoulin


1 Answers

Since Apache 2.4 you can use this expression in your .htaccess files:

<If "%{HTTP_HOST} == 'example.com'">
    AddHandler application/x-httpd-php53 .php
</If>

https://httpd.apache.org/docs/2.4/expr.html#examples

Note that this does not work in Apache 2.2.

like image 197
baru Avatar answered Sep 05 '25 14:09

baru