Tom
Tom

Reputation: 1607

Use wildcards in Symfony routing configuration for subdomain and tld

I tried to setup the Symfony routing. I'm using Symfony 2.7. I have two bundles that work under a different subdomain. The domainname can be an wild card and the tld can be multiple.

Here is my current config file:

company_api:
resource: "@ApiBundle/Controller/"
type:     annotation
prefix:   /

company_core:
resource: "@CoreBundle/Controller/"
type:     annotation
prefix:   /

I want that the first bundle only works under the subdomain "api", the domain can be an wildcard and for the TLD I want to specify a few like (nl|eu).

edited

company_core:
resource: "@ApiBundle/Controller/"
type:     annotation
prefix:   /
host:     www.mydomainname.{tld}
defaults:
    tld: nl
requirements:
    tld: "nl|eu"

I have nog upgarde the config to this setup. And the tld works correct. Only would it be possible to have an wildcard for the domain name "mydomainname"? This is easy as the dev and producten server use different doamain names.

Upvotes: 2

Views: 1412

Answers (1)

likeuntomurphy
likeuntomurphy

Reputation: 422

Here is an example of what I use on a 3.1 app, where I use a placeholder for the top-level domain that varies by environment —

app:
    resource: "@AppBundle/Controller/"
    type: annotation
    host: www.example.{tld}
    defaults:
        tld: "%tld%"
    requirements:
        tld: "%tld%"

I don’t see why the following would not work for your API routes, as this should all be compatible with 2.7 according to the docs:

company_api:
    resource: "@ApiBundle/Controller/"
    type: annotation
    host: api.{domain}.{tld}
    defaults:
        domain: yourdefaultdomain
        tld: nl
    requirements:
        tld: "nl|eu"

I do remember that during development the routing config seemed to be aggressively cached, so as always, be sure to clear the cache after making any routing changes.

Upvotes: 1

Related Questions