Redirect by language
in a multilingual website
Table of Contents
Perché questa sceltawhy
Se si ha un sito frequentato da utenti di diverse lingue (un sito multilingue) può essere utile smistare automaticamente i visitatori a seconda della loro lingua sulla rispettiva sezione del sito If you have a site frequented by users of different languages (a multilingual site) it can be useful to automatically sort visitors according to their language on the respective section of the site.
Se si usa PHP come linguaggio esiste uno script piuttosto semplice che compie questa operazione: in base alla lingua impostata come preferita nelle opzioni del browser lo script reindirizza automaticamente gli utenti verso una data cartella piuttosto che verso un'altraIf you use PHP as a language, there is a rather simple script that does this: based on the language set as preferred in the browser options, the script automatically redirects users to a given folder rather than another..
Ecco loHere the script
<?php
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2);
$lang_config = array( "it" => "ita/",
"en" => "eng/",
"fr" => "fra/",
"es" => "esp/",
"de" => "deu/",
"default" => "ita/");
if(array_key_exists($lang, $lang_config))
{
$location = $lang_config[$lang];
}
else
{
$location = $lang_config['default'];
}
header('Location: ' . $location);
?>
In questo caso chi parla italiano viene reindirizzato verso la cartella /ita/, chi parla inglese verso la cartella /eng/, e così via. Se non si trova la lingua preferita dall'utente tra quelle indicate viene reindirizzato sul default, la cartella in italiano
In this example, Italian speakers are redirected to the /ita/ folder, English speakers to the /eng/ folder, and so on. If the user's preferred language is not found among those indicated, he is redirected to the default, the folder in Italian..
Questo script era suFrom: Your inspiration web.