Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 443
yspro Avatar asked Nov 05 '22 08:11

yspro


1 Answers

<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();
  }
} ?>
like image 69
Achilles Avatar answered Nov 09 '22 16:11

Achilles