When we open many websites, we may find that they will automatically judge based on your language and jump to different language interfaces. For example, if Google is used in different languages, you can enter the Google homepage to switch to your language. In this era of network popularization, the main channel for foreign trade must be the network. Maybe your enterprise website has both Chinese and English versions (if your company has foreign trade business ). So how does their website implement this function? Next we will study the Header of the Web server. HTTP_ACCEPT_LANGUAGE is the language received by the server. It is generally the language of the server. As you can see on the website, firefox will send multiple language information when installing multiple language packs, but the first choice must be.
For example, if a Chinese user uses an English browser, the browser jumps to English. However, you can also provide language options on websites of different language versions so that they can jump over. Of course, we can use a regular expression to determine whether it contains "zh", because the first two letters of the information sent from simplified Chinese or traditional Chinese must be "zh, the following is an introduction to both Chinese and English versions:
Location/{set $ lang zh_CN; if ($ http_accept_language ~ * ^ Zh-tw) {set $ lang zh_TW; rewrite ^/$/index_zh_TW.html redirect;} if ($ http_accept_language ~ * ^ En) {set $ lang en_US; rewrite ^/$/index_en_US.html redirect ;}}
Index.html is simplified Chinese. Once you encounter the first choice of Traditional Chinese and English, you will be redirected to the correct page. Only for static homepage pages.