CURRENT PROJECTS
loading
CATEGORIES AND POSTS
loading
overset
DEVELOPMENT LOG FOR JIM PALMER
Posted 08/20/2008 in unix


Just a quick note about a re-write rule that works with Apache 2.2.X and ISAPI_rewrite v2 for IIS.

PROBLEM
You had a 5 developer team, a single development box serving each developer's sandbox and each SVN/CVS module with its own development hostname. The crux being that you'll have to put in an individual VirtualHost declaration for every combination of developer and developer SVN/CVS module that has a unique hostname.

This is assuming that each SVN/CVS module is a subdirectory that will be served with a matching sub-domain, i.e. a SVN/CVS module named
cms
will reside in the developer's sandbox as
/home/developer/cms
(classic UNIX) and be available using the
cms.dev.company.com
hostname.

This is also assuming that you have a wildcard DNS pointing *.dev.company.com to your internal Apache/IIS server so these faux domains will point to the server we're setting up the rewrite rules on.

SOLUTION
Use a mod_rewrite rule to be able to disperse requests to the appropriate developer+module without having to add, remove or modify VirtualHost declarations. Also as developers are added/removed from the team the same rewrite rule can dynamically access their modules without changes to the webserver configuration or the rewrite rules. The solution is to allow the port referred to in the HOST point to the correct developer and the last sub-domain to point to the module. Case in point: we map port 1337 to developer jim (i.e. his phone extension) and serve the cms module in his sandbox as http://cms.dev.company.com:1337/

Here's the mod_rewrite rule to allow this to happen. This should reside in some sort of default location such as the _default_ virtualhost file or in some global declaration in Apache:
RewriteEngine on
RewriteCond %{HTTP_HOST} (.*)\.dev\.company\.com:(.*) [NC]
RewriteRule ^(.*)$  /%2/%1/$1 [QSA,L]

Notes: This will allow proper passing of query string arguments. This uses the local DocumentRoot of the VirtualHost or .htaccess file's directory

In the case where we wanted to access
http://cms.dev.company.com:1337/index.php?arg1=test
The actual file that will be served is
/1337/cms/index.php?arg1=test

You should see the end of the rewrite rules log file -- if you turned on
RewriteLog
and
RewriteLogLevel 3
:
 ... go-ahead with /home/3233/cms [OK]

Another possible benefit from this configuration is to rely on accessing development sandboxes via non standard ports, i.e. [^80|443]. Leave the standard ports for serving pre-live "staging" code. In the case where all your developers are on a code-freeze for a branch release of a specific module, i.e. cms, that is to start regression testing and acceptance testing - this is the perfect time to use a staging environment off the standard ports, i.e. 80. In this case we'd add another another condition and rule to capture the default ports and direct them to the module directory instead of the developer/module directory:
RewriteEngine on
RewriteCond %{HTTP_HOST} (.*)\.dev\.company\.com [NC]
RewriteRule ^(.*)$  /%1/$1 [QSA,L]

Caveats
comments
loading
new comment
NAME
EMAIL ME ON UPDATES
EMAIL (hidden)
URL
MESSAGE TAGS ALLOWED: <code> <a> <pre class="code [tab4|tabX|inline|bash]"> <br>
PREVIEW COMMENT
TURING TEST
gravatar