【问题标题】:Redirect old urls after url rewritingurl重写后重定向旧url
【发布时间】:2011-04-22 09:38:52
【问题描述】:

我需要帮助来决定如何将旧网址重定向到新网址。 此刻我有这样的网址

myhost.com/viewrecipe.php?id=2

但我希望它们看起来像

myhost.com/recipes/pear-pie

问题是该网站已在 Google 中编入索引。有没有办法为搜索引擎编写一个 301 重定向,将它们从旧类型的 url 重定向到新类型的 url?

如果在新的 url 类型中不使用 id 就无法实现,那么还有什么其他选项可以使搜索引擎的过渡尽可能平滑?

附:所有这些都是动态网址

【问题讨论】:

    标签: seo friendly-url


    【解决方案1】:

    您可以在应用程序的根目录中使用 .htaccess 文件,其中包含:

    redirect 301 viewrecipe.php?id=2 http://www.myhost.com/recipes/pear-pie
    

    是的,您的所有 URL 都需要这...如果不是,您不能尝试编写重写,但您需要在新的 seo 友好 url 上使用 id。

    另一种方法是能够访问 viewrecipie.php?id=2 并编写如下代码:

    <?php
    // get the new name dependeind of the id
    $slug = Posts::getByID($id);
    
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: http://www.myhost.com/recipes/".$slug);
    ?>
    

    还有一条最短路径:

    header("Location: http://www.myhost.com/recipes/".$slug",TRUE,301);
    

    【讨论】:

    • 谢谢你,这些是我想到的唯一方法,你证实了它们:)
    【解决方案2】:

    您是否在重写规则后尝试过 [R=301]?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-30
      • 2011-08-07
      • 2012-10-18
      • 1970-01-01
      • 1970-01-01
      • 2016-06-27
      相关资源
      最近更新 更多