Я наконец сделал перенаправление на index.php.От 1 до 1,5 секунд до 40 мс.Что-то вроде:
<?php
$host = $_SERVER['HTTP_HOST'];
$host_a = explode('.', $host);
// if subdomain is not in the supported langs
$langs = array('en', 'es');
if( !in_array($host_a[0], $langs) ){
// try to get the cookie and the user culture
$cookie = $_COOKIE['symfony'];
list($id, $signature) = explode(':', $cookie, 2);
if( $signature == sha1($id.':'.'secret_cookie') )
{
// get cookie data from memcache
$memcache_obj = memcache_connect('localhost', 11211);
// the cookie is built with two parts separated by :
// - md5 of the sfCache directory
// - $id from the user
$md5_dir = md5(dirname(dirname(dirname(__FILE__)).'/lib/vendor/symfony/lib/cache/sfCache.class.php'));
$session = memcache_get($memcache_obj, $md5_dir.':'.$id);
$user_lang = $session['symfony/user/sfUser/culture'];
if( !in_array($user_lang, $langs) ) $user_lang = 'en';
// if not, get browser lang
}else{
$user_lang = prefered_language($langs);
}
// build url
$url = 'http://'.$user_lang.'.'.str_replace('www.', '', $_SERVER['HTTP_HOST']).$_SERVER['REQUEST_URI'];
// and redirect
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: ".$url);
die();
}
require_once(dirname(__FILE__).'/../config/ProjectConfiguration.class.php');
$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'prod', false);
sfContext::createInstance($configuration)->dispatch();