Forum Moderators: phranque

Message Too Old, No Replies

foo.com/somedir/somefile.php -> bar.com/someotherdir/someotherfile.php

if mod_proxy is not available

         

d_fused

9:05 am on Mar 30, 2005 (gmt 0)

10+ Year Member



Hi, everyone,

I have been trying to re-write a page on domain called foo.com
to point to another page on bar.com

So, when one accesses

w*ww.foo.com/somedir/somefile.php,

a page from

w*ww.bar.com/someotherdir/someotherfile.php is fetched and displayed without changing the uri.

The key point is to keep the URI intact, so users don't notice that another page from another domain is displayed (kind of hi-jacking a page and returning status code 200 OK)

I am aware that this can be done if mod_proxy is loaded by using the [P] flag in the rewrite rule, but are there any other options?

Thanks in advance for your help.

sitz

2:21 pm on Mar 30, 2005 (gmt 0)

10+ Year Member



mod_proxy is how apache does this sort of thing; other solutions are possible, but would need to be implemented in the pagecode (in a PHP script, for instance). You could, as a basic example, do something like this:

RewriteEngine on
RewriteRule ^(/path/to/file.php$) /path/to/dispatcher.php?target_url=$1 [L,QSA]

This will rewrite the request to 'dispatcher.php', passing the incoming URI as an argument. You could then have dispatcher.php tweak the 'target_url' variable (as needed) and make the outbound request to [bar.com...] and display the results; all totally transparent to the end user.

This example is likely over-simplistic; experiment with various possibilities (whatever possibilities are likely in your environment). The PHP code for a basic dispatcher shouldn't take too many lines of code; PHP has functions for HTTP requests.