aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain d'Alverny <rda@mageia.org>2011-06-29 15:53:51 +0000
committerRomain d'Alverny <rda@mageia.org>2011-06-29 15:53:51 +0000
commit1de178d99e35dba18e7b506ab801149f2a388b2d (patch)
tree9bb8fe9e66815035a6dbb08d73980298e6b6af47
parent9f1645fa00ba31f0d08906e2507bda01fea6e930 (diff)
downloadwww-1de178d99e35dba18e7b506ab801149f2a388b2d.tar
www-1de178d99e35dba18e7b506ab801149f2a388b2d.tar.gz
www-1de178d99e35dba18e7b506ab801149f2a388b2d.tar.bz2
www-1de178d99e35dba18e7b506ab801149f2a388b2d.tar.xz
www-1de178d99e35dba18e7b506ab801149f2a388b2d.zip
code to catch other mageia.* domains and redirect
-rw-r--r--langs.inc.php42
1 files changed, 38 insertions, 4 deletions
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 @@
<?php
+/**
+*/
+
+define('G_VHOST', $_SERVER['SERVER_NAME']);
// languages for home
$langs = array(
@@ -26,17 +30,47 @@ $langs = array(
'zh-tw' => '正體中文'
);
+// 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