Home > Mobile >  Match any path with a specific host [duplicate]
Match any path with a specific host [duplicate]

Time:10-05

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?

CodePudding user response:

According to the documentation found you can use . requirement to match any character in your path.

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