Page 1 of 1

Redirecting an entire domain [RESOLVED]

Posted: Tue Nov 03, 2009 8:26 am
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

Re: Redirecting an entire domain

Posted: Tue Nov 03, 2009 1:16 pm
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.

Re: Redirecting an entire domain

Posted: Wed Nov 04, 2009 7:25 am
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! :)