如何在routing.yml中重定向参数?

Chr*_*ris 13 symfony

在routing.yml中,您可以执行以下操作:

redirect_old_url_to_new:
    pattern:   /old-pattern
    defaults:  
        _controller: FrameworkBundle:Redirect:urlRedirect
        path: /new-pattern
        permanent: true
Run Code Online (Sandbox Code Playgroud)

这会将网址重定向/old-pattern/new-pattern.但是,如果我有一个参数,如何在新路径中转换参数,例如:

redirect_old_url_to_new:
    pattern:   /old-pattern/{page}
    defaults:  
        _controller: FrameworkBundle:Redirect:urlRedirect
        path: /new-pattern/{page}
        permanent: true
Run Code Online (Sandbox Code Playgroud)

这不起作用,将重定向到/new-pattern/{page}字面上,因此将重定向/old-pattern/23/new-pattern/{page}.

Ste*_*nte 16

如果参数名称相同,则参数将自动传递:

FirstRoute:
  pattern: /firstroute/{page}
  defaults:
      _controller: Bundle:Controller:action

# SecondRoute will redirect to FirstRoute. 
# ex: /secondroute/1 redirects to /firstroute/1            
SecondRoute:
  pattern: /secondroute/{page}
  defaults:
      _controller: FrameworkBundle:Redirect:redirect
      route: FirstRoute
      permanent: true
Run Code Online (Sandbox Code Playgroud)