【问题标题】:Symfony 2 - can't configure application for hostsSymfony 2 - 无法为主机配置应用程序
【发布时间】:2014-04-17 12:16:06
【问题描述】:

我在为我的 symfony 应用程序设置主机时遇到问题。现在我们有一个域,假设它是所有四种语言的 domain.pl。所以 YML 中的规则是:

front_common:
    resource: "@FrontCommonBundle/Resources/config/routing.yml"
    prefix:   /{_locale}
    defaults: { _locale: pl }
    requirements:
        _locale:  "[a-z]{2}"

front_common_locale:
    path: /
    defaults:
        _controller: FrameworkBundle:Redirect:urlRedirect
        _locale: pl
        path: /pl
        permanent: true

因此,如果有人进入 domain.pl,他/她将被重定向到 domain.pl/pl。其他页面是 domain.pl/en、domain.pl/de 等等...

现在我们得到另一个域,比如说 domain.eu,它应该只显示英文版本,所以 domain.eu 显示英文,其他人仍然重定向到 /pl /de 等。我的路由现在看起来是这样的:

front_common_eu:
    host:     domain.eu
    resource: "@FrontCommonBundle/Resources/config/routing.yml"
    prefix:   /
    defaults: { _locale: en }

front_common:
    resource: "@FrontCommonBundle/Resources/config/routing.yml"
    prefix:   /{_locale}
    defaults: { _locale: pl }
    requirements:
        _locale:  "[a-z]{2}"

front_common_locale:
    path: /
    defaults:
        _controller: FrameworkBundle:Redirect:urlRedirect
        _locale: pl
        path: /pl
        permanent: true

当我输入 domain.pl 时,它工作正常,并将我重定向到 /pl。但是当我输入 domain.eu 时,它的工作原理相同,它将我重定向到 /pl。如果我删除 fron_common_locale 路由,我会得到 404。求助,我做错了什么?

PS。据此:Routing prefix as follows the Virtual Host 它应该可以工作...

【问题讨论】:

    标签: symfony routing resources host


    【解决方案1】:

    front_common_locale 上的_locale 替换为:

    _locale: pl|en
    

    【讨论】:

    • 感谢您的回答,但没有奏效。我发现一个资源不能被包含两次。我还发现,该捆绑包:github.com/schmittjoh/JMSI18nRoutingBundle 是对我的问题如何隐藏默认语言的回答,因此该主题已解决。
    猜你喜欢
    • 1970-01-01
    • 2019-11-26
    • 2014-01-11
    • 2015-09-25
    • 2018-07-18
    • 1970-01-01
    • 2019-05-03
    • 2015-05-05
    • 2013-01-06
    相关资源
    最近更新 更多