Nginx uses rewrite to configure multilingual pages

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.