Subdomain-based symfony language selection

My symfony application should get custom language from subdomain:

ru.project.com - for English fr.project.com - for French

and so on ... A special filter gets 'GET' param 'lang' from the current uri and stores it in the user attribute. How to configure apache virtual host configuration for multiple subdomains?

+5
source share
3 answers
<VirtualHost *:80>
ServerName blah.com
ServerAlias de.blah.com en.blah.com fr.blah.com
...
</VirtualHost>

More information about server aliases: 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

Try adding them as ServerAliasin your httpd configuration file.

0
source

All Articles