Match any path with a specific host [duplicate]

  php, routes, symfony, symfony4

I want to match all paths for a specific host and redirect to a new one:

redirect_from_host:
  path:     /{uri}/
  host:     www.my-old-domain.com
  defaults:
    _controller: FrameworkBundle:Redirect:urlRedirect
    path: https://www.my-new-domain.com
    permanent: true

This works for URL’s like www.my-old-domain.com/foo/

but doesn’t with: www.my-old-domain.com/foo/bar/

So I have to add more routing definitions like:

redirect_from_host_2:
  path:     /{uri}/{uri2}/
  host:     www.my-old-domain.com
  defaults:
    _controller: FrameworkBundle:Redirect:urlRedirect
    path: https://www.my-new-domain.com
    permanent: true
redirect_from_host_3:
  path:     /{uri}/{uri2}/{uri3}/
  host:     www.my-old-domain.com
  defaults:
    _controller: FrameworkBundle:Redirect:urlRedirect
    path: https://www.my-new-domain.com
    permanent: true

and so on.

Is there any way to match all paths in one routing definition?

Source: Symfony Questions

LEAVE A COMMENT