Hello all,
I understand this topic was discussed a lot, but I'd like to now what you think of this idea.
I need to redirect a lot of old URLs to the new URLs using 301 redirect.
Here is the idea's implementation:
Create redirect.php page and set it to be default error page for 404 error (page not found) using drupal settings.
the content of the page is as following:


  if (isset($_SERVER['REQUEST_URI'])) {
    $uri = $_SERVER['REQUEST_URI'];
  }

switch ($uri)
{
  case '/cat/7/34/112/': $url="some_new_content";
	break;
  case '/cat/65/77/32' : $url="some_other_url";
	break;
}

  header( "HTTP/1.1 301 Moved Permanently" );
  header( "Status: 301 Moved Permanently" );
  header( "Location: http://my_new_site/$url" );
  exit(0);

In addition I will add header with 404 in the case statement for the default I guess.
Is this something that is going to work or not? What are the risk associated with this implementation?

Comments

firstov’s picture

I actually found this script while researching this issue.

<?php

if (isset($_SERVER['REQUEST_URI'])) { $uri = $_SERVER['REQUEST_URI']; }

$arrMoved=array("/path/oldname.php"=>"/path/newname.php",
                "/old_path/oldname.php"=>"/new_path/newname.php");
if(array_key_exists($request,$arrMoved))
    {
        $newplace="http://".$_SERVER['HTTP_HOST'].$arrMoved[$request];
        header( "HTTP/1.1 301 Moved Permanently" );
        header( "Status: 301 Moved Permanently" );
        header("Location: $newplace");
        header("Connection: close");
        exit();
    }
else
    {
            header("HTTP/1.0 404 Not Found");
    }

?>


<html>
  <head>
    <title>The page cannot be found</title>
  </head>
  <body>
    <p>The page you are looking for might have been removed, had its name
changed, or is temporarily unavailable.</p>
  </body>
</html>