简体   繁体   English

Symfony2重定向301不更改URL

[英]Symfony2 redirect 301 not changing the url

I have a simple redirectt in my routing.yml file: 我的routing.yml文件中有一个简单的重定向:

products_in_categories:
    path: /{slug}
    defaults: { _controller: MpShopBundle:Category:show }

redirect_category:
    path: /112-redirect-this
    defaults:
        _controller: MpShopBundle:Category:show
        route: products_in_categories
        slug: to-this
        permanent: true

So when I go to localhost/web/app_dev.php/112-redirect-this it should do a 301 redirect and change the url... It load the pages successfully, but the url is not changed. 因此,当我转到localhost/web/app_dev.php/112-redirect-this它应该执行301重定向并更改url ...它成功加载了页面,但url并未更改。 It shows: 表明:

localhost/web/app_dev.php/112-redirect-this when it should show: localhost/web/app_dev.php/to-this localhost/web/app_dev.php/112-redirect-this应该显示的时间: localhost/web/app_dev.php/to-this

Am I doing something wrong? 难道我做错了什么?

According to the Symfony documentation your redirecting route should point to the FrameworkBundle:Redirect:redirect action: 根据Symfony文档,您的重定向路由应指向FrameworkBundle:Redirect:redirect操作:

redirect_category:
    path: /112-redirect-this
    defaults:
        _controller: FrameworkBundle:Redirect:redirect
        route: products_in_categories
        slug: to-this
        permanent: true

It's described here: http://symfony.com/doc/current/routing/redirect_in_config.html#redirecting-using-a-route 此处描述: http : //symfony.com/doc/current/routing/redirect_in_config.html#redirecting-using-a-route

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM