In terms of dirty hacks, this has to be right up there.....
In the mysite/_config.php folder, I added:
//permanent redirections .....
$url = $_SERVER["REQUEST_URI"];
$url = substr($url, 1, 200);
if($url) {
dbcon("xxx", "xxx", "xxx", "xxx", "error connecting");
$sql = 'select count(*) FROM `SiteTree` WHERE LegacyUrl = "'.$url.'";';
if(mysqlCount($sql)) {
$sql = 'select `LegacyUrl`, `URLSegment` FROM `SiteTree` WHERE LegacyUrl = "'.$url.'";';
$data = getdata($sql);
foreach($data as $ds) {
$newLocation = str_replace("--", "-", str_replace("---", "-", "/".$ds["URLSegment"]."/"));
header("HTTP/1.1 301 Moved Permanently");
header("location: $newLocation");
die();
}
}
}
function dbcon($username, $password, $host, $mydb, $msg) {
// Database-specific information:
$connect = mysql_pconnect ($host, $username, $password) or die ($msg);
mysql_select_db ($mydb, $connect) or die ($msg);
return 1;
}
function getdata($sql) {
//returns a multidimensional array for the sql
$result = @mysql_query($sql) or die("Error: " . mysql_error()." sql was ".$sql);
$ret = array();
while($row = mysql_fetch_assoc($result)) {
$ret[] = $row;
}
mysql_free_result($result);
return $ret;
}
function mysqlCount($sql) {
$result = @mysql_query($sql) or die("Error: " . mysql_error()." sql was ".$sql);
if($result) {
if (mysql_num_rows($result) != 1) {
return false;
}
return mysql_result($result, 0,0);
}
else {
die("error in mysql_zz: ".$sql);
}
}
This gives me a redirect for all the LegacyUrls..... Surely there is a better way????
Any recommendations?