I have my app setup to use 3 subdomains, I also have 2 domains that point to the same app, giving me this set of FQDNs
admin.domain1.com, admin.domain2.com
www.domain1.com, www.domain2.com
kiosk.domain1.com, kiosk.domain2.com
In routing.yml I can set up the host / resource keys to point those domains at the relevant bundle, but I can only do it for one of the domains at a time.
incompass_admin:
host: admin.domain1.com
resource: "@IncompassAdminBundle/Resources/config/routes.yml"
incompass_web:
host: www.domain1.com
resource: "@IncompassWebBundle/Resources/config/routes.yml"
incompass_kiosk:
host: kiosk.domain1.com
resource: "@IncompassKioskBundle/Resources/config/routes.yml"
When I try something like this
incompass_kiosk_1:
host: kiosk.domain1.com
resource: "@IncompassKioskBundle/Resources/config/routes.yml"
incompass_kiosk_2:
host: kiosk.domain2.com
resource: "@IncompassKioskBundle/Resources/config/routes.yml"
The second domain is the only one that is recognised, kiosk.domain1.com throws an exception: No route found for "GET /"
Is there a way to either set the domain as a wildcard in routing.yml, or to point 2 different routes to the same resource?
edit: I've also tried to have
IncompassKioskBundle/Resources/config/routes_1.yml
IncompassKioskBundle/Resources/config/routes_2.yml
and
IncompassKioskBundle/Resources/config/routes.yml
IncompassRoutingBundle/Resources/config/kiosk_routes.yml
where the names of the routes in the 2 files are different e.g.
// routes.yml
domain_one_kiosk_scanning:
type: annotation
prefix: /
resource: Incompass\KioskBundle\Controller\ScanningController
domain_one_kiosk_printing:
type: annotation
prefix: /print
resource: Incompass\KioskBundle\Controller\PrintingController
// kiosk_routes.yml
domain_two_kiosk_scanning:
type: annotation
prefix: /
resource: Incompass\KioskBundle\Controller\ScanningController
domain_two_kiosk_printing:
type: annotation
prefix: /print
resource: Incompass\KioskBundle\Controller\PrintingController
That did not work.
You can use placeholders in routes, so try something like this:
incompass_kiosk:
host: "kiosk.{domain}.com"
resource: "@IncompassKioskBundle/Resources/config/routes.yml"
requirements:
domain: domain1|domain2
defaults: { domain: domain1 }
You could alternatively handle this in your .htaccess or virtual host configuration.
来源:https://stackoverflow.com/questions/25853472/in-symfony-2-how-do-i-handle-routing-for-multiple-domains