sthg
sthg

Reputation: 1135

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?

Upvotes: 12

Views: 19019

Answers (3)

Boldewyn
Boldewyn

Reputation: 82734

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.

Upvotes: 3

Jose Romero
Jose Romero

Reputation: 11

Hey I tried rewrite and didn't work (just tested in localhost)

Also I find this easy way

Redirect /myfolder external_url

Upvotes: -1

Gumbo
Gumbo

Reputation: 655309

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.

Upvotes: 20

Related Questions