Redirect to new domain

So I am about to redirect a complete website to a new domain. What would be the best way to redirect all those pages without loosing the ranking and traffic achieved from the old website?
With the 301 redirect does the new domain need to be hosted at the same place as the old website? Do I write the code on each page or is there a way to redirect whole website?

I tried several different ones I found searching the latest one i tried is:

Options +FollowSymLinks
RewriteCond %{THE_REQUEST} ^./index.html
RewriteRule ^(.
)index.html$ http://www.newsite.com/$1 [R=301,L]

All help appreciated!

Cheers,

Finally got it to work using the redirection at Cpanel everything seem to work expect expect for one problem i cant seem to redirect the homepage… the index page gets an error when i try to redirect it trough Cpanel… anyone ideas in why and how i can fix that? The error message is:

You cannot redirect to http://www.newsite.com as will cause a redirection loop because /home/name/public_html/ is at the same place as /home/name/public_html/.

the code the cpanel redirction uses is:

RewriteCond %{HTTP_HOST} ^mysite.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.mysite.com$
RewriteRule ^filename\-filename\-filename\-filename\.html$ “http\:\/\/www\.newsite\.com\/newfile” [R=301,L]

any ideas or suggestions?

nahoms,

You cannot redirect page rank or PR as they’re associated with the domain and page (link).

Options +FollowSymLinks
# that should be in the httpd.conf, i.e., not necessary here

RewriteEngine on
# to be sure that mod_rewrite is not in the comment mode
RewriteCond %{THE_REQUEST} ^.*/index.html
# {THE_REQUEST} is notoriously difficult to use and, as you're
# only concerned with having index.html,
# replace ALL your regex with index\\.html
RewriteRule ^(.*)index.html$ http://www.newsite.com/$1 [R=301,L]
[indent][standard rant #1][indent]The use of "lazy regex," specifically the :kaioken: EVERYTHING :kaioken: atom, (.*), and its close relatives, is the NUMBER ONE coding error of newbies BECAUSE it is "greedy." Unless you provide an "exit" from your redirection, you will ALWAYS end up in a loop![/indent][/standard rant #1][/indent]
[indent]Moreover, the (.*) COULD also capture a trailing / which leaves your redirection a mess.[/indent]

As for your next block of code:

RewriteCond %{HTTP_HOST} ^mysite[SIZE="6"]\\[/SIZE].com$ [OR]
RewriteCond %{HTTP_HOST} ^www[SIZE="6"]\\[/SIZE].mysite[SIZE="6"]\\[/SIZE].com$ [B][NC][/B]
RewriteRule ^filename\\-filename\\-filename\\-filename\\.html$ "http\\:\\/\\/www\\.newsite\\.com\\/newfile" [R=301,L]
# filename?  Is that something like ([a-z.]+)?
# newfile?  What is that?  Is Apache supposed to guess?  HOW?
# escaping -'s?  I've NEVER seen that done before!
# was that supposed to be a long string with hyphens then .html?
# do NOT escape /'s in the redirection!

Regards,

DK

hey dklynn i finally got it workin using

Code:

RewriteCond %{HTTP_HOST} ^oldomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com$
RewriteRule ^ http://www.newdomain.com [R=301,L]

How does it look? I thought that a 301 redirect make sures if all other things remain equal that you dont loose any pagerank,traffic and incoming links…

As you can see in dklynn’s post, you need to escape the dots in the RewriteConds:


RewriteCond %{HTTP_HOST} ^oldomain[SIZE="6"]\\[/SIZE].com$ [OR]
RewriteCond %{HTTP_HOST} ^www[SIZE="6"]\\[/SIZE].olddomain[SIZE="6"]\\[/SIZE].com$ 
RewriteRule ^ http://www.newdomain.com [R=301,L] 

That said, you could make it one RewriteCond instead of two since they have in common that they end in “olddomain.com”. So, remove the start anchor (^) from the first RewriteCond and it will match any domain that ends in “olddomain.com” (which also includes “www.olddomain.com”!)


RewriteCond %{HTTP_HOST} oldomain\\.com$
RewriteRule ^ http://www.newdomain.com [R=301,L] 

Another thing I’d like to point out is that any request to olddomain.com will now be redirect to the homepage of newdomain.com. That is, if a user requests olddomain.com/some/page they will be redirected to newdomain.com/ and the /some/page information is lost.
To fix this, change it to:


RewriteCond %{HTTP_HOST} oldomain\\.com$
RewriteRule .? http://www.newdomain.com%{REQUEST_URI} [R=301,L] 

You’re right about the PR, it should be transferred from olddomain.com to newdomain.com using this setup, although I’ve read that you will always loose a tiny of bit of PR when you do this (not enough to notice though).

Rémon,

Does the PR really get retained at a DIFFERENT domain? I’ll defer to those over in the SEO board but I doubt any SE would do that.

Regards,

DK

When using 301 yes, that’s the whole point of 301 :slight_smile:
Okay technically it’s not retained but transferred. You get the idea.

See http://www.sitepoint.com/forums/showthread.php?t=717439 for example (and many more in the SEO forum, just search for “301”)

thanks for the feedback guys you are lifesavers! i will try to play with it and implement your codes in. I am beginner at this so i learn by failing!

once again thanks a lot!