0

I have multiple development branches of my app, which I would like to be able to deploy on my testing server and switch between easily.

I was wondering about configuring some sort of dynamic virtual host so that on the web server I have:

/myApp/branch1
/myApp/branch2
/myApp/branch3

Which I can access via:

http://myapp.example.com/1/
http://myapp.example.com/2/
http://myapp.example.com/3/

The idea being that I can upload new branches and the virtual host will know how to serve those.

How can I do this?

Disclaimer: My knowledge of virtual hosts is limited; I would appreciate clear and simple instructions that I can learn from.

1 Answer 1

1

If all of the hostnames in the URL are the same as in your example (myapp.example.com), then all you need is a single host (main or virtual, it doesn't matter) with a RewriteRule:

RewriteEngine on
RewriteRule /(\d+)/  /myApp/branch$1

See mod_rewrite.

If the hostnames are different, then you could use mod_vhost_alias to to configure multiple virtual hosts at once. For example to map branch1.example.com to /myApp/branch1,

VirtualDocumentRoot /myApp/%1

where %1 picks up the first part of the hostname, or branch1 in this example.

2
  • I've not used mod_rewrite with virtual hosts before. Where do I put the rewrite rule within the virtual host configuration? Could you give me a solution for doing this with dynamic subdomains instead? e.g. Where the host name is branch1.example.com?
    – BadHorsie
    Sep 25, 2014 at 11:15
  • You don't need a virtual host at all; answer clarified for that. If you are using a virtual host, put the RewriteRule inside its configuration. Sep 25, 2014 at 11:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .