Host

Routes can configure a host option to require that the HTTP host of the incoming requests matches some specific value. In the following example, both routes match the same path (/) but one of them only responds to a specific host name.

1
2
3
4
5
6
7
8
9
demo_home-mobile:
   path:         /
   host:         m.demo.ddev.site
   controller:   LMS\Demo\Controller\HomePageController::mobile


demo_home-desktop:
   path:         /
   controller:   LMS\Demo\Controller\HomePageController::desktop

Tip

Required: No

The value of the host option can include parameters (which is useful in multi-tenant applications) and these parameters can be validated too with requirements.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
demo_home-mobile:
   path:         /
   host:         "{subdomain}.demo.ddev.site"
   controller:   LMS\Demo\Controller\HomePageController::mobile
   defaults:
     subdomain:  m
   requirements:
     subdomain:  m|mobile

demo_home-desktop:
   path:         /
   controller:   LMS\Demo\Controller\HomePageController::desktop

In the above example, the subdomain parameter defines a default value because otherwise you need to include a domain value each time you generate a URL using these routes.