开发者

symfony language select based on subdomain

My symfony app should get user's language from subdomain:

en.project.com - for english fr.project.com - for french

and so on... Special filter get 'GET' param 'lang' from current uri and save it in user attribute. How can I setup 开发者_开发知识库apache virtual host config for multiple subdomains?


<VirtualHost *:80>
ServerName blah.com
ServerAlias de.blah.com en.blah.com fr.blah.com
...
</VirtualHost>

Read more about server aliases: http://httpd.apache.org/docs/2.0/en/mod/core.html#serveralias

Your Symfony filter can simply parse the domain during the first request and set a session variable. This is untested but should work:

<?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();
  }
} ?>


You'll need simply to rewrite wildcard domain using mod_rewrite, and when you'll have subdomain as a parameter, you can go ahead.

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


Try to add them as ServerAlias in your httpd config file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜