How to rewrite location in nginx depending on the client-browser's language?

前端 未结 10 1891
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-02 17:25

How to rewrite location in nginx depending on the client-browser\'s language?

For example: My browser accept-language is \'uk,ru,en\'. When I request locati

10条回答
  •  有刺的猬
    2020-12-02 18:07

    I think it's not good idea to use nginx map $http_accept_language because it does not honor quality value (q in Accept-Language header). Let's imagine you have:

    map $http_accept_language $lang {
        default en;
        ~en en;
        ~da da;
    }
    

    And client will send Accept-Language: da, en-gb;q=0.8, en;q=0.7

    Using nginx map will always map $lang to en because it simply find in header string. But correct mapping will be $lang = da (because Danisch has quality value q=1 which is bigger then English q=0.7 in this case) More on this in RFC: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

提交回复
热议问题