Redirect root to a new domain

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Redirect root to a new domain

Post by klevis miho »

How can I redirect the the root of domain1.com to domain2.com/folder, but without changing the URL in the address bar (so after the redirection is done, domain1.com will be still there).
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Redirect root to a new domain

Post by VladSun »

Probably mod_rewrite could be a solution.
There are 10 types of people in this world, those who understand binary and those who don't
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Re: Redirect root to a new domain

Post by klevis miho »

Yes, but how to? :)
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Redirect root to a new domain

Post by VladSun »

What have you tried so far :P ?
There are 10 types of people in this world, those who understand binary and those who don't
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Re: Redirect root to a new domain

Post by klevis miho »

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain1\.com [NC]
RewriteRule ^(.*) http://domain2.com/$1 [R=301,L]
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Redirect root to a new domain

Post by John Cartwright »

klevis miho wrote:How can I redirect the the root of domain1.com to domain2.com/folder, but without changing the URL in the address bar (so after the redirection is done, domain1.com will be still there).
This is not possible with mod_rewrite. There is a few hacks you could do to simulate the behavior, such as an iframe (simple), or proxy (complicated + slow).
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Re: Redirect root to a new domain

Post by klevis miho »

Or with some DNS trick?
Do you know how to do it with DNS?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Redirect root to a new domain

Post by John Cartwright »

I wouldn't know how to do it with a sub folder, but you can easily turn that into a subdomain, at which point you could do this.
Post Reply