RE: In this case part of rank will be divided between old and new uri. By this idea we made system that Uri isn't change during editing of tilte.
I understand that, but it is very bad that that a misspelled url will never get indexed. The best solution would be to use a database lookup for 301 redirects. Here's some sample php code that I found that explains it better than I could.
The following example is in PHP but is easy to do with any language.
Lets say you switched to a new system and all files that ended in the
old id need to be redirected. First create a database table that will
hold the old id and the new URL to redirect to:
old_id INT
new_url VARCHAR (255)
Next, write code to populate it with your old id's and your new URLs.
Next, add the following line to .htaccess:
<code>
RewriteRule ^/product-(.*)_([0-9]+).php /redirectold.php?productid=$2
</code>
Then create the PHP file redirectold.php which will handle the 301:
<code>
<?php
function getRedirectUrl($productid) {
// Connect to the database
$dServer = "localhost";
$dDb = "mydbname";
$dUser = "mydb_user";
$dPass = "password";
$s = @mysql_connect($dServer, $dUser, $dPass)
or die("Couldn't connect to database server");
@mysql_select_db($dDb, $s)
or die("Couldn't connect to database");
$query = "SELECT new_url FROM redirects WHERE old_id = ". $productid;
mysql_query($query);
$result = mysql_query($query);
$hasRecords = mysql_num_rows($result) == 0 ? false : true;
if (!$hasRecords) {
$ret = 'http://www.yoursite.com/';
} else {
while($row = mysql_fetch_array($result))
{
$ret = 'http://www.yoursite.com/'. $row["new_url"];
}
}
mysql_close($s);
return $ret;
}
$productid = $_GET["productid"];
$url = getRedirectUrl($productid);
header("HTTP/1.1 301 Moved Permanently");
header("Location: $url");
exit();
?>
</code>
Now, all requests to your old URLs will call redirectold.php which will lookup the new URL and return a HTTP response 301 redirect to your new URL.
My opinions expressed on this site, in no way represent those of Boonex or Boonex employees.