

Nginx根据Accept-Language的简繁体支持
source link: http://maskray.me/blog/2015-10-06-nginx-accept-language-zhs-zht
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Nginx根据Accept-Language的简繁体支持
这个功能开启很久了,但直到昨天才发现遗漏了atom.xml
……
我想根据HTTP首部的Accept-Language
决定提供简体或繁体的文件。在Chrome中,chrome://settings/languages
可以设定偏好语言,浏览器会据此设置Accept-Language
首部。较好的处理方式是解析该字段,获取qvalue,根据优先级选取最恰当的语言。但仅用于支持简繁体,我想用取巧的办法:忽略优先级,只要Accept-Language
里出现了zh-Hant
、zh-TW
、zh-HK
等字样,就返回繁体,否则返回简体。
在Nginx配置文件中与server
块同级的地方加上:
我用Hexo生成网站,源文件用繁体写成。对于hexo generate
生成得到的2015-10-06-nginx-accept-language-zhs-zht.html
,用OpenCC转换得到简体版本:2015-10-06-nginx-accept-language-zhs-zht.html.zhs.html
。视情况还需要转换其他一些文件,比如atom.xml
、提供“阅读最多文章”功能的popular.json
。
在Nginx配置文件中指定需要简繁体支持的路由,
Recommend
-
8
nginx ipv6、TCP_DEFER_ACCEPT 2019-01-28 04:06:00 curl 7.61.1 curl 7.61.1 TCP_DEFER_ACCEPT
-
7
注意需要有个country-code文件。 德语,日语,英语 版本 用分支来管理三个网站 用端口来分开运行 部署测试环境一套 利用nginx map 配置 map $geoip_country_code...
-
26
The Accept-Language field in HTTP Request header is important for
-
19
[Golang] Parse Accept-Language in HTTP Request Header February 22, 2015 This post i...
-
17
Introduction To detect browser language preference (user locale), one of the solution is to access Accept-Langu...
-
9
[JavaScript] Parse Accept-Language in HTTP Request Header January 22, 2016 ...
-
7
根据时间自动切分 Nginx.log Aug 8, 2015 之前是用脚本配合 crontab 来做日志切分: #!/bin/bash # This script...
-
4
Android开发有着和ISO 639-1与BCP 47相似但不同的语言管理方案。 TL;DR...
-
9
Nginx下lua根据客户端ip进行分发 2024-01-23 1 分钟阅读 公司的线上环境分为预发布和正式两个部分。 其实两个部分是公用一个Nginx前端的。 这样怎么分发呢? 用lua即可,如果是公司来的某个固...
-
7
根据新的泄漏,Nintendo Switch 2 引擎支持 240 Hz,并可提供 40 FPS/120 Hz 模式 admin 2024年05月04日 21:48 已经有传言称Nintend...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK