Symfony2 - 文章帖子的 301 重定向

Symfony2 - 301 redirects for article posts

我对 Symfony2 和重定向还很陌生,我正在尝试将帖子从文章部分移动到网站的新部分。

此外,我是否只保留原始文章,因为它们(因为它们被 Google 的 SEO 索引)在 MySQL 数据库中,并在新部分中创建它们的新版本?

例如,

原始位置:

http://example.com/articles

http://example.com/articles/this-is-article-1

新位置:

http://exmaple.com/

http://example.com/this-is-article-1

我在 Symfony2 Cookbook 中遇到了以下内容,但我不确定我会使用哪一个。

http://symfony.com/doc/current/cookbook/routing/redirect_in_config.html

你可以做的是保留你的旧路由并在你的路由 yml 或注释中添加新路由以指向你控制器中的相同操作,这样你就可以将旧路由保留到被 SEO 索引并使用的文章你的新路线在你的树枝中,以便它们随着时间被索引,当你觉得需要你不需要旧路线时,你可以在新路线获得更好的 SEO 时删除它们。

按照您的要求重定向的另一个解决方案是:

routing.yml

root:
    path: /articles
    defaults:
        _controller: FrameworkBundle:Redirect:redirect
        route: new_route_name_articles_index
        permanent: true

这会将您的http://example.com/articles重定向到您创建的新路由