From 1de178d99e35dba18e7b506ab801149f2a388b2d Mon Sep 17 00:00:00 2001 From: Romain d'Alverny Date: Wed, 29 Jun 2011 15:53:51 +0000 Subject: code to catch other mageia.* domains and redirect --- langs.inc.php | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) (limited to 'langs.inc.php') diff --git a/langs.inc.php b/langs.inc.php index 78e0deab5..7409f5b9d 100644 --- a/langs.inc.php +++ b/langs.inc.php @@ -1,4 +1,8 @@ '正體中文' ); +// TODO (rda) define fallback languages for each language +// for instance, pt-br could fallback on pt and pt on pt-br (but without +// a cycle) then on es, etc. $i18n_fallback_rules = array( 'pt-br' => 'pt', 'pt' => 'pt-br' ); -// TODO (rda) define fallback languages for each language -// for instance, pt-br could fallback on pt and pt on pt-br (but without -// a cycle) then on es, etc. +$domains_lang = array( + 'mageia.fr' => 'fr', + 'mageia.it' => 'it', + 'mageia.ro' => 'ro', +); + +/** + * Redirect to a localized path, depending on incoming TLD. + * Only manages redirections to main home path. + * + * @param string $host + * @param array $domains_lang + * @param string $vhost + * + * @return void +*/ +function domain_redirect($host, $domains_lang, $vhost) +{ + $host = str_replace('www.', '', $host); + + if (array_key_exists($host, $domains_lang)) { + $path = $domains_lang[$host] . '/'; + header ('HTTP/1.1 301 Moved Permanently'); + } else { + $path = '?langs'; + } + header(sprintf('Location: %s://%s/%s', 'http', $vhost, $path)); + die; +} + /** - * Redirect to a localized path. + * Redirect to a localized path, after browser Accept-Language prefs. * * @param array $langs list of languages * @param string $page optional path to which we want to redirect -- cgit v1.2.1