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:
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/.
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!
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…
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”!)
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:
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).