I've written a PHP script that functions perfectly for this. It is my 404 ErrorDocument so when a bad (old) url is entered this script processes it and redirects the user to the new page. As I said it works perfectly, but not for search engines! For some reason they are not picking up on the 301 Redirect, but the 404.
How do I stop ErrorDocument 404 from sending header 404, or how do I overwrite the header 404 with 301?
A bit more information:
If you were to go to the old url http://lonewolf-online.net/computer.php you are automatically redirected to http://lonewolf-online.net/computers fine, but google seems to be stopping at a 404 Not Found.
My redirect code looks like this: (I have already scripted the variables $page to extract from the request_uri)
switch($page)
{
case "index.php"; redirectURL('/'); break;
case "about.php"; redirectURL('/about'); break;
case "astro.php"; redirectURL('/astronomy'); break;
case "cars.php"; redirectURL('/cars'); break;
case "computer.php"; redirectURL('/computers'); break;
...
}
function redirectURL($newrl)
{
//Custom logging procedure here
//
//Finally redirect to new page
header("HTTP/1.1 301 Moved Permanently");
header("Location: $newrl");
}
I've done it this way because some of the old urls have upto 5 parameters which may or may not exist and the new urls require that each parameter is passed. For example my blog:
function redirectBlog($params)
{
$section = $params['section'];
if (!$section)
$section = "all";
$section = str_replace(" ", "_", $section);
$section = str_replace("%20", "_", $section);
$section = strtolower($section);
$blogitem = $params['blogitem'];
if ($blogitem != "")
{
$section = "permalink";
$blogitem = 'item' . $blogitem;
}
$start = $params['start'];
if (!$start)
$start = "0";
redirectURL('/blog/' . $section . '/' . $start . '/' . $blogitem);
}
I couldn't see how this would work in a .htaccess file.
Thanks in advance...
Tim