Apache: redirect subfolder to another IP in the LAN

I have webserver1 behind a router currently serving all http traffic to mydomain.com. I just added webserver2, and want to redirect mydomain.com/server2 traffic to that box. To the user, the redirect should be unnoticed (i.e. the URL should just be mydomain.com/server2, and the redirection happens behind the scenes). How do I set this up in the apache configuration of webserver1 (I'm assuming webserver2's config needs to do nothing special)?

I've tried the advice given here, using mod_rewrite, but it didn't seem to do the trick:

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/server2/
RewriteRule ^/$ http://192.168.1.102/ [P,L]

In case it is relevant, webserver1 is hosting a django app using mod_wsgi, with a few other apps that get redirected away. Here is the virtualhost conf:

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName  www.mydomain.com
    ServerAlias 127.0.0.1

    RewriteEngine on
        RewriteCond %{REQUEST_URI} ^/server2/
        RewriteRule ^/$ http://192.168.1.102 [P,L]

    DocumentRoot /var/www
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog /var/log/apache2/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

    <Directory /var/www/mydomain>
    Order allow,deny
    Allow from all
    </Directory>

    ...

    WSGIDaemonProcess mydomain user=user group=user threads=25
    WSGIProcessGroup mydomain

    WSGIScriptAlias / /home/user/mydomain/apache/django.wsgi
    Alias /phpmyadmin /usr/share/phpmyadmin/

</VirtualHost>

Thanks in advance.


Mod_Rewrite is more flexible than mod_proxy. Uncomment the load line for it.

Simple comparison here http://www.wellho.net/mouth/1376_Choosing-between-mod-proxy-and-mod-rewrite.html

<VirtualHost *:80>

RewriteEngine on

# just in case (don't want to accidentally expose all the internal servers) !
ProxyRequests off

# define a log file
RewriteLog /var/log/apache/server2.rewrite.log
RewriteLogLevel 1

# add the tailing / if not there
RewriteRule     ^/server2$          http://www.mydomain.com/server2/  [R] [L]

# proxy the request to internal url
RewriteRule     ^/server2/(.*)      http://192.168.1.102/$1 [P]

Note that this example is case sensitive.