Redirecting an entire domain [RESOLVED]

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
marcus27
Forum Newbie
Posts: 4
Joined: Thu Mar 26, 2009 11:32 am

Redirecting an entire domain [RESOLVED]

Post by marcus27 »

I am changing a site's domain name and looking for a way to redirect any traffic to the original domain name, let's call that "siteA.com", to the new one, "siteB.com". I currently use several header type redirects which work great for individual pages, but now I am looking for a way to redirect all visitors to any page on "siteA.com" to "siteB.com", not just visitors to a specific page.
I am hoping to find an easy way to do this with PHP, short of adding the header function to every page, or perhaps some non-PHP method (htaccess?).

I want a visitor to end up on "siteB.com/index.php" regardless of whether he/she visits
siteA.com/abc/index.php
or
siteA.com/def/index.php
or
siteA.com/xyz/index.php
etc...

I can't be the first person to want to change a site's URL so there must be some easy way to do it. If anyone could point me in the right direction, it would be greatly appreciated :).

Marcus
Last edited by marcus27 on Wed Nov 04, 2009 7:26 am, edited 1 time in total.
Gadgetmo
Forum Newbie
Posts: 14
Joined: Sun Nov 01, 2009 7:17 am

Re: Redirecting an entire domain

Post by Gadgetmo »

Create a file called .htaccess in the root directory of the old website.

In there put:

Code: Select all

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://siteB.com/index.php [R=301,L]
Replace

Code: Select all

http://siteB.com/index.php
with your new domain.

Hopefully, that should work.
marcus27
Forum Newbie
Posts: 4
Joined: Thu Mar 26, 2009 11:32 am

Re: Redirecting an entire domain

Post by marcus27 »

Gadgetmo wrote:Create a file called .htaccess in the root directory of the old website.

In there put:

Code: Select all

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://siteB.com/index.php [R=301,L]
Replace

Code: Select all

http://siteB.com/index.php
with your new domain.

Hopefully, that should work.
Thanks, that's exactly what I was looking for. A bonus is that this method will even redirect for non-existing files as long as the URL points to the directory with the .htaccess file or one of its sub-directories. Pretty neat.

Thanks! :)
Post Reply