Search code examples
symfonyhttp-redirectrouteshttp-status-code-301

Symfony2 - 301 redirects for article posts


I'm fairly new to Symfony2 and redirects, I am trying to move posts from an articles section into a new section of a website.

Also, do I just leave the original articles as they (as they are indexed with Google's SEO) are in the MySQL database and create new versions of them in the new section?

E.g.,

original location:

http://example.com/articles

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

new location:

http://exmaple.com/

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

I've come across the following in the Symfony2 Cookbook but I am unsure which one I would use.

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


Solution

  • What you can do is to keep your old routing and add new route in your routing yml or annotation to point to the same action in your controller, this way you keep your old routing to articles which are SEO indexed and use your new routes in your twigs so that they get indexed with time, when you feel the need you don't need the old routing you can delete them when the new routes get better SEO.

    Another solution which is redirecting as you asked is this :

    routing.yml

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

    This will redirect your http://example.com/articles to your new routing that you created