View Single Post
  #7  
Old 04-19-2006, 06:02 AM
Coop Coop is offline
Member
GB Beginner
 
Join Date: Apr 2006
Posts: 34
Default

Oops, just spotted a typo, and I can't edit the original post. Please ignore the above script and use :-

Code:
<?php
$map = array(
'/old/1.html' => '/new/2.html',
'/old/2.php' => '/newlocation/3.html');

if (isset($map[$_SERVER['REDIRECT_URL']])) {
    $new_loc = 'http://' .
               $_SERVER['HTTP_HOST'] .
               $map[$_SERVER['REDIRECT_URL']];
    if (isset($_SERVER['REDIRECT_QUERY_STRING'])) {
        $new_loc .= '?' .
                    $_SERVER['REDIRECT_QUERY_STRING'];
    }
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: $new_loc");
} else {
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: ".$_SERVER['HTTP_HOST']);
}
?>
instead. I missed out the header line in the original.


Also, it is possible to use .htaccess to redirect all files in one location to another, providing the directory structure of the destination remains the same. But the last time I tried that, I got lots of odd problems occuring with other SEO rules in the .htaccess file, so I changed to using the php script instead, which is much easier to maintain IMO.
__________________
Coop
Reply With Quote