homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

RewriteRule used to rewrite domains
Retrieving content invisibly.

10+ Year Member

Msg#: 416 posted 2:02 pm on Oct 15, 2003 (gmt 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?




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

Msg#: 416 posted 2:31 pm on Oct 15, 2003 (gmt 0)

You may want to start with this thread and see the tip from ergophobe [webmasterworld.com...]


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

Msg#: 416 posted 2:48 pm on Oct 15, 2003 (gmt 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.



10+ Year Member

Msg#: 416 posted 2:59 pm on Oct 15, 2003 (gmt 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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved