Forum Moderators: phranque

Message Too Old, No Replies

domain redirection

Standard redirection of the domain

         

vwsequeira

4:58 am on Nov 6, 2006 (gmt 0)

10+ Year Member



Hello,

The following Mod_rewrite code redirects the domain 'example.com' to 'quux-foo.org'. But the browser address bar URL displays 'quux-foo.org' :

RewriteEngine On
RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^example.com/$ [NC,OR]
RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^www.example.com/$ [NC]
RewriteRule ^(.*)$ [quux-foo.org...] [L]

Can you please tell me how to keep the address bar URL unchanged when the redirection goes fine to quux-foo.org?

Vincent

[edited by: jdMorgan at 12:13 pm (utc) on Nov. 6, 2006]
[edit reason] Examplified [/edit]

jtara

5:51 am on Nov 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



(Please don't use real domain names. Use "example.com, example2.com, etc.)

You can't. It's doing exactly what you told it to do.

Do you want to redirect, or not? User types in A, you want it to go to B instead. That's what it's doing. They get to B, it's going to show B in the browser URL bar.

vwsequeira

6:48 am on Nov 7, 2006 (gmt 0)

10+ Year Member




Thank you, Is there any alternative method or code if you tell me to redirect the domain name so that browser URL shouldn’t change?

I really appreciate your help and I don’t have much exposure to mod rewrite

jtara

7:30 am on Nov 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm having a bit of trouble understanding just what you are trying to accomplish. I think you're jumping ahead to what you think the solution is, rather than telling us what problem you are trying to solve.

Do you have control over both servers? Is one a subdomain or a directory on somebody else's server? (i.e. a blog, etc.?)

If you do a redirect from domain A, all it does is send the browser to domain B. Domain B is still domain B. You want to say "go to domain B, and pretend it is domain A".

Think of the implications of what you are trying to do: if it worked, anybody could hijack your website and make it look like it was theirs.

Why don't you do it the other way around? Redirect from domain B to domain A?

You have to decide which one you want as your "primary" domain. Once you decide, do the redirect from the "secondary" domain to the "primary" one.

If you want common content on both, simply set your "A" records for both domains to point to the same server. You need to be careful to only use relative references in your internal links, and be careful of any stray references to the site name in your HTML files. (You can use server-side includes to deal with this.)

Another way is to "frame" the second site, but this is a poor substitute. This is commonly done by people who have, say, a subdomain on a blogging site, and want to use their own domain. Very dependent on how the blogging software does it's internal links, etc.

vwsequeira

12:44 pm on Nov 7, 2006 (gmt 0)

10+ Year Member



Sorry for not being clear in the previous reply.

I want domainA.com show the content of domainB.com . Acutally I am not experecing any difficuties with hosting or redirecting the domains. I just want the visitors of my old site go to domainA.com go to domainB.com. I want to accomplish this just using mod rewrite code rather editing the zone file of the domain.

Thank you,

Vincent

cduke250

1:03 pm on Nov 7, 2006 (gmt 0)

10+ Year Member



RewriteEngine On
RewriteCond %{HTTP_HOST} ^.*example.com$ [NC]
RewriteRule ^(.*)$ [quux-foo.org$1...] [QSA,L]

[edited by: jatar_k at 12:28 am (utc) on Nov. 21, 2006]
[edit reason] no urls thanks [/edit]

cduke250

1:06 pm on Nov 7, 2006 (gmt 0)

10+ Year Member



If your server allows it then you should use the P flag

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^.*example\.com [NC]
RewriteRule ^(.*)$ [quux-foo.org...] [P]

[edited by: jatar_k at 12:28 am (utc) on Nov. 21, 2006]

cduke250

1:08 pm on Nov 7, 2006 (gmt 0)

10+ Year Member



If you are simply trying to redirect all users from domainA.com to domainB.com then it is simple

RewriteEngine On
RewriteCond %{HTTP_HOST} ^.*example.com$ [NC,OR]
RewriteRule ^(.*)$ [quux-foo.org$1...] [R=301,L,QSA]

jtara

2:24 pm on Nov 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you are simply trying to redirect all users from domainA.com to domainB.com then it is simple

But then he wants the URL in the browser bar to read domainA.com... Does not compute... :)

I'm still not quite understanding. Please confirm, this is what I think you want:

- domainA is your OLD site.

- domainB is your NEW site.

- You want users who go to domainA to be redirected to domainB.

- But once they get to domainB, you want domainB to masquerade as domainA. (Show domainA in the browser bar.)

Is this correct?

If so, you can't accomplish this by making changes only on domainA's website.

What do you want the user to see if they navigate directly to domainB?

It sounds to me like you are just changing web hosts. Why not just change the A record?