I just migrated (with mod rewrite
) from non-friendly URLs to a bit-more-friendly URLs: from site.com/post.php?id=5
to site.com/post/the-title-of-the-post/5
.
This is my PHP redirect from old to new URL:
if(empty($_GET['friendly']) && empty($_POST)){
include('includes/basedatos.php');
include('includes/funciones.php');
$id = (int) mysql_real_escape_string($_GET['id']);
$post = mysql_fetch_array(mysql_query("SELECT id, titulo FROM post WHERE id = $id"));
$titulo = $post['titulo'];
if($titulo == ''){
header('HTTP/1.0 404 Not Found');
}
$ruta = '/post/'.urls_amigables(trim($titulo)).'/'.$id;
header ('HTTP/1.1 301 Moved Permanently'); /* please not this */
header("Location: $ruta");
exit();
}
The problem here is that even I set the headers to 301 Google is warning me of duplicated titles (and descriptions) and shows me both (old and new) URLs.
Question: is this a temporary stage? or I am not moving properly the my post URLs?