symfony/symfony — pull request #3002 by blogsh (2011-12-30 12:22:01+00:00)
Title: [Routing] Add a '_host' requirement for routes

Today I wanted to add different routes for different hosts in a project. Therefore I added a new _host requirement to the routing system. This makes it possible to work with several host names in one symfony installation. It can be easily added to any route like

_welcome:
pattern: /
requirements: { _host: 'example.org' }

It is quite useful when you define routes as annotations, because you can set a host for a whole controller:

/**
* @Route(requirements={"_host"="example.org"})
*/
class MyController { ... }

I also added an UrlGenerator so it is possible to generate urls just like before. The only difference is that an absolute URL will be generated if the current request has not the same host name.

Maybe it could be a bit more flexible to define host routes, but it is a first attempt. What do you think?