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();
}
} ?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With