# Routing a request depending on the host and route

**URL:** <https://discourse.cakephp.org/t/routing-a-request-depending-on-the-host-and-route/10660>\
**Category:** Need Help\
**Created:** [October 6, 2022, 11:14am UTC](https://discourse.cakephp.org/t/routing-a-request-depending-on-the-host-and-route/10660 "2022-10-06T11:14:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mvojwe](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@mvojwe](https://discourse.cakephp.org/u/mvojwe)\
**Post date:** [October 6, 2022, 11:14am UTC](https://discourse.cakephp.org/t/routing-a-request-depending-on-the-host-and-route/10660/1 "2022-10-06T11:14:59Z")

</div>

I have two symbolic links that I cannot change on my [example.com](http://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:

- [example.com/restapi/086](http://example.com/restapi/086) requests to my Api/V1 prefix
- [example.com/restapi/087](http://example.com/restapi/087) requests to my Api/V2 prefix

This is what I’ve tried:  
routes.php

```auto
$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](http://example.com) and I shouldn’t include the full path there. How can I rewrite my code to make it work? Thanks in advance.

---

<div class="post-metadata">

**Author:** ![jarekgol](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@jarekgol](https://discourse.cakephp.org/u/jarekgol)\
**Post date:** [October 10, 2022, 10:00pm UTC](https://discourse.cakephp.org/t/routing-a-request-depending-on-the-host-and-route/10660/2 "2022-10-10T22:00:38Z")

</div>

What don’t you separate this into 2 independent `->connect()` without scope?  
like at the beginning of [Routing - 4.x](https://book.cakephp.org/4/en/development/routing.html)

---

<div class="post-metadata">

**Author:** ![mvojwe](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@mvojwe](https://discourse.cakephp.org/u/mvojwe)\
**Post date:** [October 11, 2022, 12:43pm UTC](https://discourse.cakephp.org/t/routing-a-request-depending-on-the-host-and-route/10660/3 "2022-10-11T12:43:14Z")

</div>

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 “/”
