Symfony 重定向 - routers.yaml 在 annotations.yaml 之前

Symfony redirects - routers.yaml before annotations.yaml

我在我的项目中使用注释,但要使用 routes.yaml 进行重定向 如果存在路由(例如 /home name="home"} 则重定向不起作用:

home-301:
    path: /home
    defaults:
        _controller: FrameworkBundle:Redirect:urlRedirect
        path: /new-home
        permanent: true

我找到了解决方案,但我认为这不是好的做法:

已清除:config/routes/annotations.yaml 并附加到文件的末尾 config/routes.yaml:

controllers:
  resource: ../../src/Controller/
  type: annotation

怎么做才对?

我的解决方案:

所有重定向放入:config/routers/redirects.yaml

和config/routes.yaml:

redirects:
  resource: routes/redirects.yaml

annotations:
  resource: routes/annotations.yaml