We're a web development shop and have our sites checked out from SVN on a single development server via samba, like this:

share/
    site1/
        trunk/
    site2/
        trunk/
        branches/
            feature-branch1/
            feature-branch2/

This works by assigning a TLD .web to point to that server so you can say site1.web or site2.web in any workstation and it works.

What I would like to do is allow users to switch between branches (which includes trunk) on the same URL, so when you say site1.web, you should be able to choose which branch you're looking at. This way we can have a streamlined naming scheme and you always know where stuff is (the idea is to attach a color-coded bar at the top of the site so you're aware that you're on a different branch, you could also choose branches there too).

I've started with something like this:

<VirtualHost *:80>
    RewriteEngine On

    # if stage var __stage set in Request, use it
    RewriteCond %{QUERY_STRING} __stage=([a-z\/]+) [NC]
    RewriteRule ^/(.*) /$1 [CO=__stage:%1:.site1.web,R,L]

    # if no stage cookie set, default to /trunk
    RewriteCond %{HTTP_COOKIE} !__stage
    RewriteRule ^/(.*) /$1 [CO=__stage:/trunk:.site1.web,R,L]

    # extract stage from cookie value and use it as path inside DocumentRoot
    RewriteCond %{HTTP_COOKIE}  __stage=([^;]+)
    RewriteRule (.*) %1/index.php [QSA,NC,L]

    DocumentRoot    /share/site1
    DirectoryIndex  index.php
    ServerName  www.site1.web
    ServerAlias     site1.web
</VirtualHost>

This works (not all of it, still working on it), but has an issue of having to go through mod_rewrite for every single file and feels really fragile.

Am I on the right track here or is there something else I'm not aware of? I'm not interested in changing the development workflow.

link|improve this question
feedback

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
or
required, but never shown

Browse other questions tagged or ask your own question.