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

前端 未结 10 1945
爱一瞬间的悲伤
爱一瞬间的悲伤 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 17:41

    Simple solution, without MapModule and AcceptLanguageModule :

       if ( $http_accept_language ~ ^(..) ) {
             set $lang $1;
       }
       set $args hl=$lang&$args;
    

    Note that the "set $args hl=$lang&$args" sets the desired language code (eg. "en", "fr", "es", etc) in the "hl" query parameter. Of course you can use $lang in other rewriting rules if the query parameter does not fit. Example:

    location ~/my/dir/path/ {
              rewrite ^/my/dir/path/ /my/dir/path/$1/ break;
              proxy_pass http://upstream_server;
       }
    

提交回复
热议问题