Forum Moderators: phranque
// redirect old traffic to redirect script
RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
RewriteRule ^dir1/dir2/view\.pl$ /redir.php? [L]
<?php
// get id from the querystring
$legacy_id = htmlspecialchars($_GET["id"]);
// db Connection
$dbhost = 'xxx';
$dbuser = 'xxx';
$dbpass = 'xxx';
$dbname = 'xxx';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
//Query
$query = ("SELECT ua.dst
FROM content_type_artwork cta
JOIN url_alias ua
ON ua.src = CONCAT('node/',cta.nid)
WHERE cta.field_legacy_art_id_value = $legacy_id");
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$new_path = $row['dst'];
}
// close connection
mysql_close($conn);
// Permanent redirection
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.example.com/$new_path");
exit();
?>
// redirect old traffic to redirect script
[0-9]* will allow a "blank" id to be passed to the PHP script. You should use [0-9]+ here.