It is really an Apache question you've most likely run into before. I wish to have one source package will be able to deploy to my workstation, my staging server, and my production server, but for this to load different .htaccess configurations according to exactly what the URL was.

Observe that I had been utilizing a kludge by having an IfModule call, but that will not use our new production server since it shares the same modules as my staging server.

Note I have to bundle SetEnv with one of these rewrites. Presently if you are using RewriteCond, it only ties towards the following RewriteRule, although not the SetEnv underneath.

Rather than using SetEnv, make use of the atmosphere variable setting abilities of RewriteRule itself:

RewriteCond %{HTTP_HOST}
RewriteRule ^ - [E=VARNAME:foo]

RewriteCond %{HTTP_HOST}
RewriteRule ^ - [E=VARNAME:bar]

Although I favor carrying this out kind of factor by passing flags towards the httpd process at startup and searching for them using IfDefine blocks.

<IfDefine FOO>
SetEnv VARNAME foo

<IfDefine BAR>
SetEnv VARNAME bar

On Ubuntu Linux, the IfDefine's variable is occur


and it is known as APACHE_ARGUMENTS. So, at the end of this file I needed to add:

export APACHE_ARGUMENTS="-D dev"

...after which bounce the server with:

/etc/init.d/apache2 stop
/etc/init.d/apache2 start

However, there is a Debian article about this subject that talks about this here. For the reason that example, the file to edit is /etc/default/apache2 and also the variable is known as APACHE_DEFINES.

Likewise, on some systems it's a variable named OPTIONS that's occur /etc/sysconfig/httpd.

So, what you will need to do is search for the beginning section inside your apache2ctl file. So, begin using a "whereis apache2ctl" to locate where that script is, cat it and discover the beginning section using the apache2 directive inside it, if the variable it passes is OPTIONS, APACHE_ARGUMENTS, APACHE_DEFINES, or something like that else. Then, see which file you have to edit by experimentation with either /etc/sysconfig/httpd, /etc/default/apache2, or /etc/apache2/envvars.

This is a simple example that needs to be enough that you should change it out to satisfy your needs:

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteBase /

    RewriteCond %{HTTP_HOST} !^localhost
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]