Forfly 翔!
Mr. Le's personal blog, life, love and others. 人生就像是旅行,不必在乎目的地,只在乎沿途的风景!
All Rights reserved by Mr. Le

根据浏览器语言跳转不通网页

为了让不同语言显示不同网站/网页,故很多商业网站有这个需求。

两个办法:

  1. PHP 语言实现:在PHP中用header(“location:test.php”)进行跳转要注意以下几点:1、location和“:”号间不能有空格,否则会出错。2、在用header前不能有任何的输出。3、header后的PHP代码还会被执行。

这个方法也不能禁止所有的浏览器,因为IE浏览器的代号见最后,其他的浏览器code不等。比如google chrome只认可ZH,而没有ZH-CN

部分浏览器对 英语还做了区分,比如EN-US, EN-GB, EN-IN

<?php
  if ($_SERVER["HTTP_ACCEPT_LANGUAGE"] == "en")
    header("location: ../press_en.php");//如果是EN英文转到press_enphp
  else 
    header("location: ../press_de.php");//如果是De德文转到德文php页面
?>

 

  1. htacess文件实现:生成htacess文件,输入如下代码!
# START
RewriteEngine on
# IF EN, REDIRECT TO PRESS_EN.PHP
RewriteCond %{HTTP:Accept-Language} (en) [NC]
RewriteRule .* server.com/press_en.php [L]


RewriteCond %{HTTP:Accept-Language} (de) [NC]
RewriteRule .* server.com/press_de.php [L]

 

暂且记录,还没验证!

 

The following codes are those used by Firefox and other web browsers to indicate to web servers which languages they are prepared to accept. Web servers can make decisions on which content to serve based on these codes.

They are typically transmitted in the HTTP header “HTTP_ACCEPT_LANGUAGE”.

Code Language Code Language Code Language
af Afrikaans hr Croatian el Greek
sq Albanian cs Czech gu Gujurati
ar Arabic (Standard) da Danish ht Haitian
ar-dz Arabic (Algeria) nl Dutch (Standard) he Hebrew
ar-bh Arabic (Bahrain) nl-be Dutch (Belgian) hi Hindi
ar-eg Arabic (Egypt) en English hu Hungarian
ar-iq Arabic (Iraq) en-au English (Australia) is Icelandic
ar-jo Arabic (Jordan) en-bz English (Belize) id Indonesian
ar-kw Arabic (Kuwait) en-ca English (Canada) iu Inuktitut
ar-lb Arabic (Lebanon) en-ie English (Ireland) ga Irish
ar-ly Arabic (Libya) en-jm English (Jamaica) it Italian (Standard)
ar-ma Arabic (Morocco) en-nz English (New Zealand) it-ch Italian (Switzerland)
ar-om Arabic (Oman) en-ph English (Philippines) ja Japanese
ar-qa Arabic (Qatar) en-za English (South Africa) kn Kannada
ar-sa Arabic (Saudi Arabia) en-tt English (Trinidad & Tobago) ks Kashmiri
ar-sy Arabic (Syria) en-gb English (United Kingdom) kk Kazakh
ar-tn Arabic (Tunisia) en-us English (United States) km Khmer
ar-ae Arabic (U.A.E.) en-zw English (Zimbabwe) ky Kirghiz
ar-ye Arabic (Yemen) eo Esperanto tlh Klingon
ar Aragonese et Estonian ko Korean
hy Armenian fo Faeroese ko-kp Korean (North Korea)
as Assamese fa Farsi ko-kr Korean (South Korea)
ast Asturian fj Fijian la Latin
az Azerbaijani fi Finnish lv Latvian
eu Basque fr French (Standard) lt Lithuanian
bg Bulgarian fr-be French (Belgium) lb Luxembourgish
be Belarusian fr-ca French (Canada) mk FYRO Macedonian
bn Bengali fr-fr French (France) ms Malay
bs Bosnian fr-lu French (Luxembourg) ml Malayalam
br Breton fr-mc French (Monaco) mt Maltese
bg Bulgarian fr-ch French (Switzerland) mi Maori
my Burmese fy Frisian mr Marathi
ca Catalan fur Friulian mo Moldavian
ch Chamorro gd Gaelic (Scots) nv Navajo
ce Chechen gd-ie Gaelic (Irish) ng Ndonga
zh Chinese gl Galacian ne Nepali
zh-hk Chinese (Hong Kong) ka Georgian no Norwegian
zh-cn Chinese (PRC) de German (Standard) nb Norwegian (Bokmal)
zh-sg Chinese (Singapore) de-at German (Austria) nn Norwegian (Nynorsk)
zh-tw Chinese (Taiwan) de-de German (Germany) oc Occitan
cv Chuvash de-li German (Liechtenstein) or Oriya
co Corsican de-lu German (Luxembourg) om Oromo
cr Cree de-ch German (Switzerland) fa Persian
fa-ir Persian/Iran
Code Language Code Language
pl Polish sx Sutu
pt Portuguese sw Swahili
pt-br Portuguese (Brazil) sv Swedish
pa Punjabi sv-fi Swedish (Finland)
pa-in Punjabi (India) sv-sv Swedish (Sweden)
pa-pk Punjabi (Pakistan) ta Tamil
qu Quechua tt Tatar
rm Rhaeto-Romanic te Teluga
ro Romanian th Thai
ro-mo Romanian (Moldavia) tig Tigre
ru Russian ts Tsonga
ru-mo Russian (Moldavia) tn Tswana
sz Sami (Lappish) tr Turkish
sg Sango tk Turkmen
sa Sanskrit uk Ukrainian
sc Sardinian hsb Upper Sorbian
gd Scots Gaelic ur Urdu
sd Sindhi ve Venda
si Singhalese vi Vietnamese
sr Serbian vo Volapuk
sk Slovak wa Walloon
sl Slovenian cy Welsh
so Somani xh Xhosa
sb Sorbian ji Yiddish
es Spanish zu Zulu
es-ar Spanish (Argentina)
es-bo Spanish (Bolivia)
es-cl Spanish (Chile)
es-co Spanish (Colombia)
es-cr Spanish (Costa Rica)
es-do Spanish (Dominican Republic)
es-ec Spanish (Ecuador)
es-sv Spanish (El Salvador)
es-gt Spanish (Guatemala)
es-hn Spanish (Honduras)
es-mx Spanish (Mexico)
es-ni Spanish (Nicaragua)
es-pa Spanish (Panama)
es-py Spanish (Paraguay)
es-pe Spanish (Peru)
es-pr Spanish (Puerto Rico)
es-es Spanish (Spain)
es-uy Spanish (Uruguay)
es-ve Spanish (Venezuela)
2017-03-03
暂无评论

发表回复