I am currently in the process of setting up an Apache server that will be hosting projects built from SVN using a continuous integration server. The problem is, however, that while I've managed to configure the build server to output the revisions of a project to a directory, I'm stumped as to how to actually configure Apache using mod_vhost_alias to serve the different projects.

The directory structure is generated using the following pattern:


Inside, there are two directories which I'd like to configure access via a subdomain:

api.r[revision].testserver.local -> ./server

r[revision].testserver.local -> ./web

There is already a local DNS server that serves the wildcards on *.testserver.local and already resolves them to the correct IP, but Apache needs to resolve the correct DocumentRoot for the different subdomains.

The end result I'm hoping for is that as long as the build server outputs and configures the projects inside /usr/share/Projects/r*, Apache will know how to resolve these subdomains without the need to write conf files and reloading configurations each time a new revision is fetched and built from SVN.

| improve this question | | | | |

Just set up IP based virtual host and inside put

RewriteEngine on
RewriteLog "/private/var/log/apache2/rewrite.log"
RewriteCond %{HTTP_HOST} ^api.*
RewriteRule   ^(.+)     %{HTTP_HOST}$1          [C]
RewriteRule   ^api\.r(.+)\.server\.local(.*) /Users/uros/Sites/testserver/r$1/server/$2

RewriteCond %{HTTP_HOST} ^r*
RewriteRule   ^(.+)     %{HTTP_HOST}$1          [C]
RewriteRule   ^r(.+)\.server\.local(.*) /Users/uros/Sites/testserver/r$1/web/$2

You don't need default DocumentRoot set. And don't forget that your VirtualHost need to answer on all domains, so it's better to put this host on a separate IP or include virtualhost definition first (if none found first one is used)

P.S. I know the code could be optimized, but this one works ;)

| improve this answer | | | | |
  • Would this work with relative paths, ie. having r$1/server/$2 instead of the absolute path? Trying to make the setup as bulletproof as possible. – Klemen Slavič Apr 8 '11 at 8:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.