开发者

Multi-Lingual Site with subdomains

I want to make a multi-lingual website that defaults to English like example.com with subdomains like fr.example.com, de.example.com, it.example.com ...

now, if the user selects fr.example.com, the site's language will be French.

if the subdomain is fr, PHP will include lang_fr.php, if de, PHP will includ开发者_StackOverflow社区e lang_de.php, but if there is no subdomain, PHP must include the default file lang_en.php

The site must have only one source code, content and style, it must use the same resources that will be in the root of example.com.

So how to use Apache to rewrite the URL from fr.example.com to example.com/index.php?lang=fr and example.com/ to example.com/index.php?lang=en


You don't need to rewrite anything. Just check $_SERVER['SERVER_NAME'].

function get_language()
{
  //not tested
  $default_language = 'en';
  $language = array_shift(explode('.', $_SERVER['SERVER_NAME'] ));
  if ( str_len( $language ) > 2 )
  {
    $language = $default_language;
  }
  return $language;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜