在 Symfony2 路由中,如何设置一个可选的子域
In Symfony2 routing, how do I setup an optional subdomain
我在我的项目中使用了几个子域,我想让主要营销站点接受 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
我能让它工作的唯一方法是使用不同类型的路由。
app/config/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/Resources/config/routes.yml
incompass_web_main:
type: annotation
prefix: /
resource: Incompass\WebBundle\Controller\MainController
IncompassWebBundle/Resources/config/routes_two.yml
incompass_web_main_two:
path: /
defaults: { _controller: IncompassWebBundle:Main:index }
我在我的项目中使用了几个子域,我想让主要营销站点接受 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
我能让它工作的唯一方法是使用不同类型的路由。
app/config/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/Resources/config/routes.yml
incompass_web_main:
type: annotation
prefix: /
resource: Incompass\WebBundle\Controller\MainController
IncompassWebBundle/Resources/config/routes_two.yml
incompass_web_main_two:
path: /
defaults: { _controller: IncompassWebBundle:Main:index }