【问题标题】:In Symfony2 routing, how do I setup an optional subdomain在 Symfony2 路由中,如何设置可选的子域
【发布时间】:2015-03-05 19:50:00
【问题描述】:

我在我的项目中使用了一些子域,我想让主要营销网站接受 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

【问题讨论】:

  • 你不能复制主域的路由吗?
  • 那行不通,我已将我尝试的内容添加到主要问题中

标签: symfony routing


【解决方案1】:

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

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 }

【讨论】:

    猜你喜欢
    • 2011-07-18
    • 1970-01-01
    • 2012-05-27
    • 2017-07-18
    • 2014-09-17
    • 2012-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多