Q:

Mod-rewrite rule for external pages?

Is it possible use mod_rewrite to resolve addresses hosted on another server?
Say I want to setup this URL:
http://www.myserver.com/myfolder/

To actually resolve to:
http://www.anotherserver.com/anotherfolder/

If so, could you provide a RewriteRule example? 

A:

You can use the P flag in a mod_rewrite rule to get that substitution URL requested by mod_proxy:
RewriteEngine on
RewriteRule ^myfolder/$ http://other.example.com/anotherfolder/ [P]

Now when a client is requesting /myfolder/ from your server, it will request http://other.example.com/anotherfolder/ and send the response from that server back to the client.

A:

No, tunneling is not possible, you'd have to use a CGI script for this. However, you can redirect:
RewriteRule  ^(.*)  http://new.example.com/$1

with or without the [R] flag, and it will automatically redirect the user to the new domain.
Edit: Apparently it is possible to tunnel requests with mod_proxy and the [P] flag. See Gumbo’s answer.

