Maybe something like (using michael's code, no coffee yet, so this is not bugfree, but you'll get the idea:
PHP Code:
<?php
if ($_GET['p'])
{
$p = intval($_GET['p']);
$postid = $DB_site->query_first("SELECT postid FROM " . TABLE_PREFIX . "post
WHERE import_id = $p");
header("Location: http://www.yoursite.com/forum/showthread.php?" . p=$postid#$postid);
}
else if ($_GET['t'])
{
$p = "t=" . intval($_GET['t']);
}
?>
And the same for threadid, but you'll figure that out.