【问题标题】:symfony language select based on subdomain基于子域的symfony语言选择
【发布时间】:2010-09-14 09:25:06
【问题描述】:

我的 symfony 应用应该从子域中获取用户的语言:

en.project.com - 英文版 fr.project.com - 法语

等等…… 特殊过滤器从当前 uri 中获取 'GET' 参数 'lang' 并将其保存在用户属性中。 如何为多个子域设置 apache 虚拟主机配置?

【问题讨论】:

  • 我的咖啡应该是热的,但它是微温的..

标签: php internationalization symfony1


【解决方案1】:
<VirtualHost *:80>
ServerName blah.com
ServerAlias de.blah.com en.blah.com fr.blah.com
...
</VirtualHost>

阅读有关服务器别名的更多信息:http://httpd.apache.org/docs/2.0/en/mod/core.html#serveralias

您的 Symfony 过滤器可以在第一次请求期间简单地解析域并设置会话变量。 这是未经测试的,但应该可以工作:

<?php class localeFilter extends sfFilter
{
  public function execute($filterChain)
  {
    // Execute this filter only once
    if ($this->isFirstCall()) {
      $host = $_REQUEST['HTTP_HOST'];
      $locale = array_shift(explode(".",$host));
      $this->getUser()->setAttribute('locale', $locale);
    }

    // Execute next filter
    $filterChain->execute();
  }
} ?>

【讨论】:

    【解决方案2】:

    您只需使用 mod_rewrite 重写通配符域,当您将子域作为参数时,您可以继续。

    http://www.easymodrewrite.com/example-subdomains

    【讨论】:

      【解决方案3】:

      尝试在您的 httpd 配置文件中将它们添加为 ServerAlias

      【讨论】:

        猜你喜欢
        • 2018-08-30
        • 1970-01-01
        • 1970-01-01
        • 2012-12-31
        • 2013-02-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多