2015-06-08 39 views
-1
多条路线

比方说,我有多个(子)域的网站:具有多个域

  • acme.com(USA)
  • acme.nl(荷兰)
  • be.acme .eu域名(比利时)
  • de.acme.eu(德国)
  • fr.acme.eu(法国)
  • 等...

我想这应该是配置非常简单,所以我做了这个的routing.yml:

usa: 
    host: "acme.com" 
    resource: "@WebsiteBundle/Controller/" 
    type:  annotation 
    defaults: 
     country: "en" 

netherlands: 
    host: "acme.nl" 
    resource: "@WebsiteBundle/Controller/" 
    type:  annotation 
    defaults: 
     country: "nl" 

europe: 
    host: "{country}.acme.eu" 
    resource: "@WebsiteBundle/Controller/" 
    type:  annotation 

但是,如果我跑router:debug,只有最后一个路径(在这种情况下{country}.acme.eu)显示出来。如果我更改为订单,最后一个选项显示。

如何为我所有的国家使用不同的(子)域?

回答

1

这是因为所有的路由指向一个资源。每条稍后的路线都会覆盖之前定义的路线

但是你可以用另一种解决方案:

main_route: 
    host: "{country}.acme.{domain}" 
    resource: "@WebsiteBundle/Controller/" 
    type:  annotation 
    defaults: 
     country: "en" 

然后在一些监听控制器,有效的URL和工艺参数前检查。

+0

我认为你是对的,这是不可能有多个路由/ hosts中指出,一个资源:http://github.com/symfony/ symfony/issues/6857 –

0

您应该使用Symfony的hostname routing

所以,你的路线将如下所示:

international_homepages: 
    path: /
    host:  "{subdomain}.acme.{extension}" 
    defaults: 
     _controller: AcmeBundle:Main:defaultHomepage 
     subdomain: www 
     extension: com 
+0

你的答案和我的相比有什么新东西? –