nginx实现多语言跳转不同的url

nginx实现多语言跳转不同的url

server {
        listen       80;
        server_name www.text.com;

        location / {

            if ($http_accept_language ~* ^zh)       {
                set $lang zh_CN;
                rewrite (.*)  https://www.baidu.com$1 permanent;
                break;
            }

            if ($http_accept_language ~* ^ko)       {
                set $lang ko_KR;
                rewrite (.*)  https://www.aliyun.com$1 permanent;
                break;
            }
            if ($http_accept_language ~* ^en)       {
                set $lang en_US;
                rewrite (.*)  https://www.google.com$1 permanent;
                break;
            }
        }

}

测试

curl -I http://www.text.com -H "Accept-Language:ko"
curl -I http://www.text.com -H "Accept-Language:zh"
curl -I http://www.text.com -H "Accept-Language:en"


$ curl -I http://www.text.com -H "Accept-Language:zh"
HTTP/1.1 301 Moved Permanently
Server: WPWS/1.0.0
Date: Wed, 06 Mar 2019 06:13:29 GMT
Content-Type: text/html
Content-Length: 281
Connection: keep-alive
Location: https://www.baidu.com/
Expires: Sat, 16 Mar 2019 06:13:29 GMT
Cache-Control: max-age=864000


$ curl -I http://www.text.com -H "Accept-Language:ko"
HTTP/1.1 301 Moved Permanently
Server: WPWS/1.0.0
Date: Wed, 06 Mar 2019 06:14:05 GMT
Content-Type: text/html
Content-Length: 281
Connection: keep-alive
Location: https://www.aliyun.com/
Expires: Sat, 16 Mar 2019 06:14:05 GMT
Cache-Control: max-age=864000

$ curl -I http://www.text.com -H "Accept-Language:en"
HTTP/1.1 301 Moved Permanently
Server: WPWS/1.0.0
Date: Wed, 06 Mar 2019 06:20:56 GMT
Content-Type: text/html
Content-Length: 281
Connection: keep-alive
Location: https://www.google.com/
Expires: Sat, 16 Mar 2019 06:20:56 GMT
Cache-Control: max-age=864000

转载于:https://www.cnblogs.com/xiaogongzi/p/10483086.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值