Conditional include for .htaccess file

.htaccess

is it possible to conditionally include another file in the htaccess file. When i work locally my apache settings are different from my remote server.

Each time i pull in changes through git to the stage site (which shares the same settings as the live server) i have to apply a patch to my htaccess:

diff --git a/.htaccess b/.htaccess
index 4733ffa..1b39d24 100644
--- a/.htaccess
+++ b/.htaccess
@@ -2,6 +2,15 @@
 # Apache/PHP/Drupal settings:
 #

+############################################
+## uncomment these lines for CGI mode
+## make sure to specify the correct cgi php binary file name
+## it might be /cgi-bin/php-cgi
+
+  Action php5-cgi /cgi-bin/php5-cgi
+  AddHandler php5-cgi .php
+
+

Is there a way to conditionally include this into my htaccess file. Thus, i could just gitignore this particular include file.

I could do a git hook but i'm not well versed and not interested in investing time at this moment to learn that.

P.S. if you're curious what my patch does is it provides the stage server directives as to where to run php as cgi.

Best Answer

Apache allows <IfDefine> and <IfModule> directives within .htaccess files.

If you want to use <IfDefine> then Apache needs to be started as httpd -Dsomedefinition. See here.

<IfModule> is useful if you only want certain directives to be enabled if a given Apache module is loaded (e.g. if mod_perl has been loaded). See here.

Related Topic