【问题标题】:Symfony2 redirect 301 not changing the urlSymfony2重定向301不改变网址
【发布时间】:2016-12-19 02:19:10
【问题描述】:

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

所以当我转到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

我做错了吗?

【问题讨论】:

标签: php symfony redirect


【解决方案1】:

根据 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

【讨论】:

  • 天哪,我还以为你需要在那里写下你的控制器位置...谢谢!!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-07-01
  • 2015-03-05
  • 2013-03-30
  • 2011-04-17
  • 2016-09-01
  • 2010-12-03
  • 2012-11-25
相关资源
最近更新 更多