Redirecting a specific URL to a different vhost in apache

I have two versions of a very small ruby-on-rails apps running on my web server. One is served externally (production) and one is served only on an intranet URL (staging). So I have two Virtual Hosts setup and they work well.

My goal is to serve up the generated documentation for the code base underneath the domain of the staging server, but just setup a different vhost and docroot and dump all the static HTML files there. I'm unclear how to set this up in httpd.conf.

So, the goal is to have:

staging.foo.com/ -> rails app vhost (pointed at /var/www/rails/foo/)

and

staging.foo.com/doc/ -> documentation vhost (pointed at /var/www/doc/foo/)

Sorry about the clumsiness of the question; I'm pretty sure this can be done with mod_rewrite but after reading through the docs several times I'm still lost as to how to accomplish this Feat of Strength.


You can specify the rewrite rule like it's shown in this example :

<VirtualHost 172.20.30.40>
   DocumentRoot /www/subdomain/sub2
   ServerName www.sub2.domain.tld
   ServerPath /sub2/
   RewriteEngine On
   RewriteRule ^(/sub2/.*) /www/subdomain$1
 </VirtualHost>

Use the ServerPath like you want (doc in your example) and then use RewriteRule to bind the ServerPath to your new location. Don't forget the $1 (matched part).

Don't forget to load mod_rewrite in apache.