我在路由中有一个简单的重定向。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
所以当我去localhost/web/app_dev.php/112-redirect-this
它应该做一个301重定向和改变url…它成功加载了页面,但是url没有改变。它表明:
localhost/web/app_dev.php/112-redirect-this
时应该显示:localhost/web/app_dev.php/to-this
我做错了什么吗?
根据Symfony文档,您的重定向路由应该指向FrameworkBundle:Redirect:redirect
动作:
redirect_category:
path: /112-redirect-this
defaults:
_controller: FrameworkBundle:Redirect:redirect
route: products_in_categories
slug: to-this
permanent: true
说明如下:http://symfony.com/doc/current/routing/redirect_in_config.html#redirecting-using-a-route