2015-06-08 36 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

你的答案和我的相比有什麼新東西? –