Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

RewriteRule used to rewrite domains

Retrieving content invisibly.

2:02 pm on Oct 15, 2003 (gmt 0)

New User

10+ Year Member

joined:Oct 15, 2003
votes: 0

Hello there,

This is my first (registered) question here and it's been puzzling me for a while now. It's easiest described with an example.

Say I have the domains:
available to me.

What I want to do is...
Anything put through domain.com is reflected from the content of otherdomain.com/~user without the path in the 'location' bar of the browser changing.

would actually receive it's content from
BUT visitors would see the path in their browser as http://(www.)mydomain.com/blah.html and all the images/hyperlinks/etc would [i]appear to link to the mydomain.com domain.

I currently use the following code in a .htaccess file on mydomain.com to redirect the user from mydomaincom to the other, but the 'location' in the browser also changes.

## --------------------
## --------------------
RewriteEngine On
RewriteRule ^(.*) http://otherdomain.com/~user/$1

Is there any way to do what I'm trying to do?


2:31 pm on Oct 15, 2003 (gmt 0)


WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
votes: 1

You may want to start with this thread and see the tip from ergophobe [webmasterworld.com...]
2:48 pm on Oct 15, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
votes: 0


Welcome to WebmasterWorld [webmasterworld.com]!

The cause of the updated URL in the user's address bar is that you have specified a full URL rather than a local path.

You can do a "silent" or "transparent" redirect only if the substitute resource is actually on the same server and in the same "account" as the the resource originally requested. This may be the case if you have two or more domains hosted in the same account. If the content you wish to serve is actually hosted on another server, then there is no way to use mod_rewrite or mod_alias to serve the content; You'll have to use an iframe or advanced scripting instead.

If, however, the content is actually hosted on the same server, you can accomplish your goal by using only a local path as the substitution URI:

RewriteEngine On
RewriteRule ^(.*) /~user/$1 [L]

Let's say you want to serve content from [maindomain.com...] whenever someone requests content from [[b]user[...] . Then you'd use something like this:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^(.*)\.maindomain\.com
RewriteRule ^(.*) /~%1/$1 [L]

Note that in both examples, no [R] flag is used and the substitution URI is a local path only.


2:59 pm on Oct 15, 2003 (gmt 0)

New User

10+ Year Member

joined:Oct 15, 2003
votes: 0

Thankyou both for the extremely fast response!

I have created a (seemingly) working system. I simply redirect all requests to a php page on mydomain.com which processes everything and spits out the remote file (yes, I know there's a massive server load but hey, it works).

Basically, it was a modification of the code used in this article [alistapart.com].


P.S. If anyone knows another way other than redirecting to a PHP page and grabbing the remote file into PHP's memory then you're welcome to elaborate here.