最近做SEO优化,要求返回正确的Content-Language;
response.setHeader("Content-Language", "ja");//这个设置没用,这个值跟操作系统有关
于是在nginx重写这个值,简略配置如下;
环境 :http://localhost/french;http://localhost/japanese........等;
location /{ proxy_hide_header 'Content-Language'; #隐藏掉之前的值 if ($request_uri ~* "/china"){ #根据不同的国家添加不同的值 add_header Content-Language cn; } if ($request_uri ~* "/japanese"){ add_header Content-Language ja; } if ($request_uri ~* "/french"){ add_header Content-Language fr; } proxy_pass http://home_server; } rewrite /china /test/index.do?locale=cn&custom=1 last; rewrite /french /test/index.do?locale=fr&custom=2 last; rewrite /japanese /test/index.do?locale=ja&custom=3 last; rewrite ^/(.*) /test/index.do?locale=$1&custom=4 last;
以上代码在nginx-1.5.3 windows平台上测试通过.
请看官方文档:
Note that for headers other than Last-Modified
, it just appends a new header entry to the output header list. So you can't use this directive to rewrite existing headers likeServer
. Use the headers_more module for it.
大概意思是说add_header这个参数不能修改 Last-Modified
除这个之外的值,如果你要修改,使用headers_more 这个扩展.由于我在windows上测试的,没法编译扩展到nginx,so用上面的办法!(╰_╯)#..