views:

311

answers:

3

Is it possible to configure Apache web server to map a directory to a path on another web server? For example, can I make requests for http://server1/resource/ return http://server2/resource/. If this is possible, how do I go about setting this up?

+2  A: 

mod_rewrite is pretty powerful for this. You'd setup a rewrite rule for /resource/ and use a 302 redirect to send people over to server two.

http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html

http://www.modrewrite.com/

Untested example:

<location "/">
 RewriteEngine On
 RewriteRule ^/resource/(.*)$ http://server2/resource/$1 [R]
</location>
Crad
A: 

I think this question is for serverfault.com. Not going in detail here, but you could set this up using RewriteCond, RewriteRule directives in apache configuration.

I have used both mod_proxy and mod_rewrite rules to achieve similar effect. PS: check out serverfault.com and give the sysadmin folks a try.

Ryan Oberoi
Agreed that this would have been better on ServerFault.com
Crad
+1  A: 

mod_proxy is the way to go:

http://httpd.apache.org/docs/2.0/mod/mod_proxy.html

Use:

<Location /resource/>
    ProxyPass http://server2/resource/
    SetEnv force-proxy-request-1.0 1
    SetEnv proxy-nokeepalive 1
</Location>
stevedbrown
The only disadvantage here is in a high request per second environment, you are proxying, and thus leaving the backend on apache open while you go to the other server and process. This requires more open connections and may be slower than just sending the browser to the right server with a http header.
Crad
While I did answer the question as stated, on an architectural level in a high volume environment, I agree that you don't want to do this with Apache.
stevedbrown