Routing a request depending on the host and route

I have two symbolic links that I cannot change on my example.com server, both redirecting to the same cake app:

  • public_html/restapi/086 => /home/user/cake_app/webroot
  • public_html/restapi/087 => /home/user/cake_app/webroot

My goal is to redirect:

This is what I’ve tried:
routes.php

$routes->scope('/', function (RouteBuilder $builder) {

    $host = "example.com/restapi/086/";
    $builder->connect('/', ['prefix' => 'Api/V1', 'controller' => 'V1', 'action' => 'index'])->setHost($host);

    $host = "example.com/restapi/087/";
    $builder->connect('/', ['prefix' => 'Api/V2', 'controller' => 'V2', 'action' => 'index'])->setHost($host);
}

This is not working since the host is only example.com and I shouldn’t include the full path there. How can I rewrite my code to make it work? Thanks in advance.

What don’t you separate this into 2 independent ->connect() without scope?
like at the beginning of Routing - 4.x

I cannot do that because restapi/086 and restapi/087 are the names of the symbolic links on the server. Both requests end up with the base path “/”