Thanks Ryan, so this means to get for example interview_id=819 redirected to the correct article, I have to provide the ID also in the new URL?
TLD/category/category.php?interview_id=819
to
TLD/category/interview-name-819
Should be something like this in Regex:
RewriteRule ^category/([^/]+-)?([0-9]+)/?$ category/category.php?interview_id=$2
EDIT: After working on it the whole day I found the following solution (as I'm working with Wordpress). Maybe it is useful for anyone:
I'm using the following function now:
add_action('parse_request','oldsite_redirect',0); // 0=before (most) 'parse_request' calls
function oldsite_redirect() {
if (isset($_GET['interview_id'])) {
global $wpdb;
$sql = "SELECT post_id FROM {$wpdb->postmeta} " .
"WHERE meta_key='interview_id' AND meta_value='%s'";
$sql = $wpdb->prepare($sql,$_GET['interview_id']);
$post_id = $wpdb->get_var($sql);
if ($post_id) {
$permalink = get_permalink($post_id);
if ($permalink) {wp_safe_redirect($permalink,301);
exit;}
}
}
}
Solution found here: http://wordpress.stackexchange.com/questions/12824/url-rewrite-based-on-a-custom-field-value/