在Symfony2路由中,如何设置可选子域

时间:2015-01-07 19:55:18

标签: symfony routing

我在项目中使用了一些子域名,我希望主营销网站接受www以及空白子域名

http://www.example.com& http://example.com

如何使用symfony实现这一目标?

这是我当前的设置

_main:
    resource: routing.yml

incompass_sterilization:
    host:     spd.casechek-dev.com
    resource: "@IncompassSterilizationBundle/Resources/config/routes.yml"

incompass_printing:
    host:     labels.casechek-dev.com
    resource: "@IncompassPrintingBundle/Resources/config/routes.yml"

incompass_admin:
    host:     admin.casechek-dev.com
    resource: "@IncompassAdminBundle/Resources/config/routes.yml"

incompass_web:
    host:     www.casechek-dev.com
    resource: "@IncompassWebBundle/Resources/config/routes.yml"

我查看了此处的文档http://symfony.com/doc/current/components/routing/hostname_pattern.html,但我只能看到如何设置存在的不同子域,我无法弄清楚如何使用空子域。

修改 复制路由不起作用,我无法获得多个路由使用相同的控制器。以下是2个未解决问题的示例

使用相同的路线文件

incompass_web:
    host:     www.casechek-dev.com
    resource: "@IncompassWebBundle/Resources/config/routes.yml"

incompass_web_two:
    host:     casechek-dev.com
    resource: "@IncompassWebBundle/Resources/config/routes.yml"

使用单独的路线文件

incompass_web:
    host:     www.casechek-dev.com
    resource: "@IncompassWebBundle/Resources/config/routes.yml"

incompass_web_two:
    host:     casechek-dev.com
    resource: "@IncompassWebBundle/Resources/config/routes_two.yml"

routes.yml

incompass_web_main:
    type: annotation
    prefix: /
    resource: Incompass\WebBundle\Controller\MainController

routes_two.yml

incompass_web_main_two:
    type: annotation
    prefix: /
    resource: Incompass\WebBundle\Controller\MainController

1 个答案:

答案 0 :(得分:0)

我能让它工作的唯一方法是使用不同类型的路由。

应用程序/配置/ routing.yml中

_main:
    resource: routing.yml

incompass_sterilization:
    host:     spd.casechek-dev.com
    resource: "@IncompassSterilizationBundle/Resources/config/routes.yml"

incompass_printing:
    host:     labels.casechek-dev.com
    resource: "@IncompassPrintingBundle/Resources/config/routes.yml"

incompass_admin:
    host:     admin.casechek-dev.com
    resource: "@IncompassAdminBundle/Resources/config/routes.yml"

incompass_web:
    host:     www.casechek-dev.com
    resource: "@IncompassWebBundle/Resources/config/routes.yml"

incompass_web_two:
    host:     casechek-dev.com
    resource: "@IncompassWebBundle/Resources/config/routes_two.yml"

IncompassWebBundle /资源/配置/ routes.yml

incompass_web_main:
    type: annotation
    prefix: /
    resource: Incompass\WebBundle\Controller\MainController

IncompassWebBundle /资源/配置/ routes_two.yml

incompass_web_main_two:
    path: /
    defaults: { _controller: IncompassWebBundle:Main:index }
相关问题