Edit
It seems that it's my provider (OVH) who allows that kind of redirect within its infrastructure.
See : https://docs.ovh.com/gb/en/domains/redirect-domain-name/
I'm keeping the answer below for the sake of archiving, but it doesn't provide any meaningful information for other DNS providers.
Original answer
I did that using a TXT record.
To redirect foo.bar.com to foo2.bar.com/path, just add foo IN TXT "1|foo2.bar.com/path" in your bar.com DNS zone.
It also keeps the url paths and parameters. So if you try to access foo.bar.com/hello?foo=bar, you'll be redirected to foo2.bar.com/path/hello?foo=bar.