1

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?

3 Answers 3

1

If your requests to the old URLs are actually redirected with status 301 to the new URLs (check with Firebug or similar), Google will notice sooner or later and drop the old ones from the index. The bot has probably indexed the new pages and not (yet) checked the old URLs that are already indexed. Your headers look fine for me.

Note below: ideally, you should take care that all links on the page actually use the new URLs, not sure whether this is the case.

1
  • True, the number of warnings has already decreased.. thanks! Commented Oct 1, 2013 at 14:33
1

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.

Use the Fetch as Google to see if there's any Crawl Errors for the new friendly URLs. If they're reachable, then it just might take some time for Google Webmaster Tools to update.

Some things you can do to prevent further crawling and indexing for the non-friendly URLs:

  • Disallow URLs with those parameters from being indexed in your robots.txt:

    Disallow: /*?id=

  • Tell Google not to crawl URLs with those parameters - see the bottom of the following and select No URLs: Specify how Google should handle parameters

  • Also be sure to remove the non-friendly URLs from your sitemap and add the friendly URLs to it.

You can verify that Google has indexed the new friendly URLs by using this search operator:

site:domain.com/post/the-title-of-the-post/5

1
  • Did you happen to notice that I also indicated it would just take some time (prior to the other answer), and provided some options to possibly speed this up?
    – dan
    Commented Oct 2, 2013 at 4:14
0

You have factors with database type sites like Drupal and Wordpress, etc. one is your post appears stand alone, tags, archives and categories and now after all these years this is a problem. I just posted a related question today as well. 301 these variations or find a way to remove these factors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.