Sunday, February 27, 2005

nice 301 redirect with mapping

Add to Delicious Digg this links to this post -

Just came across this problem, and this is a nice one for search marketers. How to move an old site to a new one, while mapping old pages to new ones with as less hassle as possible.

1) create a correspondance table in excel, 1 column for old urls, 1 column for new ones, following this modele:

/page1.html http://www.yournewssite/pagex.html
/page2.html http://www.yournewssite/pagey.html
etc ...

=> then export it as tab delimited text file, save it as redirect.txt, and upload it onto your server, at the html root.

2) create redirect.php which looks like this:
$file = "http://www.youroldsite.com/redirect.txt";
$default = "http://www.yournewsite.com";

$url = $_GET["url"];
$lines = file($file);

foreach ($lines as $line){
$array = explode (chr(9), $line);
$start = $array[0];
$landing = $array[1];
if ($start == $url){
header("HTTP/1.1 301 Moved Permanently");
header("Location: $landing");
exit();
}
}
header("HTTP/1.1 301 Moved Permanently");
header("Location: $default");
?>

3) add this url rewriting directives to your .htaccess file:
RewriteEngine on
RewriteRule ^(.*).html$ /redirect.php?url=/$1.html [L]
RewriteRule ^$ /redirect.php [L]

That's it, once you have uploaded the .htaccess, the redirect is then carried over smoothly, without changing anything to your html files.

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home