Forum Moderators: phranque
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.
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.