Symfony2 - 301重定向文章帖子

时间:2015-03-20 02:48:35

标签: symfony redirect routing http-status-code-301

我是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

1 个答案:

答案 0 :(得分:2)

您可以做的是保留旧路由并在路由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重定向到您创建的新路由

相关问题