Page is a not externally linkable
3Mice - 8:47 am on Jan 7, 2009 (gmt 0)
Now the reason i asked was that the current site i am managing has been completely redesigned from scratch. Initially it was hosted on a Windows server but now will be on a Linux server. The problem i faced was that the old site has hundreds of links in this form http://www.example.com/folder/page.asp?oldid=1 where the id changes and these links were bringing tremendous traffic indexed by google.. Obviously when we moved to the Linux server the .asp pages would not work so the problem was to figure how to redirect the search engine traffic coming in from the .asp pages to redirect to the new pages on the linux server.. The new page link look something like this http://www.example.com/folder/productpage.htm The first thing i did on the .htaccess file was to add this code.. RewriteCond %{QUERY_STRING} ^oldid=(.+)$ to redirect any traffic coming in from the old .asp pages to the redirection.php page to get the new link corresponding to the old id. I created a table called redirection in the database that stores the old id number in one column (id_number) and the corresponding link of the new page in the next column (new_link) Column name ¦ Value Here is the code on the redirection.php page === $s = @mysql_connect($dServer, $dUser, $dPass) @mysql_select_db($dDb, $s) $query = "SELECT new_link FROM redirection WHERE id_number = ". $productid; $productid = $_GET["id"]; header("HTTP/1.1 301 Moved Permanently"); ======== he is redirected to http://www.example.com/folder/productpage.htm with the 301 headers sent to the search engine..What do you think? Is this good and safe enough? So far on the local machine everything is working ok Thanks [edited by: jdMorgan at 2:09 pm (utc) on Jan. 7, 2009]
I had posted a question on this subforum here
[webmasterworld.com...]
where i wanted to know how to do 301 redirects through the .htaccess file. I got positive responses from all of you..thanks
RewriteRule ^folder/page.asp$ http://www.example.com/redirection.php?id=%1 [R=301,L]
eg
=========== =====
id_number ---> 1
new_link ---> folder/productpage.htm
<?php
function getRedirectUrl($productid) {
// Connect to the database
$dServer = "localhost";
$dDb = "database";
$dUser = "username";
$dPass = "password";
or die("Couldn't connect to database server");
or die("Couldn't connect to database");
mysql_query($query);
$result = mysql_query($query);
$hasRecords = mysql_num_rows($result) == 0 ? false : true;
if (!$hasRecords) {
$ret = 'http://www.mysite.com/';
} else {
while($row = mysql_fetch_array($result))
{
$ret = 'http://www.example.com/'. $row["new_link"];
}
}
mysql_close($s);
return $ret;
}
$url = getRedirectUrl($productid);
header("Location: $url");
exit();
?>
So if someone comes to our site through the old link http://www.example.com/folder/page.asp?oldid=1
[edit reason] Please use example.com -- It can never be owned. [/edit]