Change your site domain or path keeping your Google PageRank and position

When a website moves from an URL to another, the main issue for the webmaster is try to keep a good position on the Google search results (or other search engines).
Time ago I applied the SEO technique described in this article and I obtained good results.

The goal, in this example, is to move the site located in http://www.youroldsite.com/section/ to the new location http://www.yournewsite.com/section/.

The trick to map everything to the new location (without specifying every single URL) and especially to tell correctly to Google to consider that the site has moved (as described in Google FAQ) is to use the HTTP response code 301 that causes a Permanent Redirect.

Obviously everything inside the section directory must keep exactly its previous relative path. I.e. http://www.youroldsite.com/section/page.html have to be placed in http://www.yournewsite.com/section/page.html.
It’s even possible, using regular expression, to map relative paths that have some differences, but a “logic” between them should exist.

A .htaccess file should be placed inside the document root or in the section subdirectory of the old website where the site is moving out
The content of .htaccess should look like this:

RedirectMatch 301 ^/section/(.*)$ http://www.yournewsite.com/section/$1

Obviously if the new site has section moved in othersection the .htaccess should look like this:

RedirectMatch 301 ^/section/(.*)$ http://www.yournewsite.com/othersection/$1

And if the relocation has happened within the same domain:

RedirectMatch 301 ^/section/(.*)$ /othersection/$1

A test made with wget (a GNU tool):

Connecting to www.youroldsite.com|127.0.0.1|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://www.yournewsite.com/section/ [following]
--2009-03-24 20:04:59--  http://www.yournewsite.com/section/
Resolving www.yournewsite.com... 127.0.0.1
Connecting to www.yournewsite.com|127.0.0.1|:80... connected.
HTTP request sent, awaiting response... 200 OK

I applied the first configuration to one of my websites that was in the first position on Google for some query strings, because unluckily I had to move it on a new domain name.

The result has been very good. After 7 days I placed the Redirect 301, my old URL (that was the first position of Google) has been replaced by the new one. Still in the first position, and it’s still there!