views:

143

answers:

2

Hi, 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?

-thanks

+1  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.

Boldewyn
Cool thanks, the user would see the refresh in this case? (ie: address bar will show http://new.example.com). When you say i'd need a CGI script, could you give me some clues as to what i should look for ? cheers
sthg
Yes, the user would see the new URL. If you don't want this, google (or search on StackOverflow) for "proxy software".
Boldewyn
Great - thanks buddy.
sthg
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.

Gumbo