关于Apache内容协商的语言切换机制
语言分配设置
在 httpd.conf 文件中新增内容。
# vim /etc/httpd/conf/httpd.conf
<Directory "/var/www/html">
Options +MultiViews
DirectoryIndex index
重新启动Apache。
# service httpd restart
准备文件
# ls -l /var/www/html/
-rw-r--r-- 1 root root 17 2015-02-27 00:38 index.html.en
-rw-r--r-- 1 root root 34 2015-02-27 00:37 index.html.ja
确定
# curl -H 'Accept-Language: ja, en;q=0.8' localhost
# curl -H 'Accept-Language: en, ja;q=0.8' localhost
# curl -H 'Accept-Language: ja-jp, ja, en-us, en;q=0.8' localhost
填补
「ja-jp」和「en-us」不包含在默认的Apache配置中,需要适当添加。
# grep AddLanguage /etc/httpd/conf/httpd.conf
# DefaultLanguage and AddLanguage allows you to specify the language of
# language code is pl) may wish to use "AddLanguage pl .po" to
AddLanguage ca .ca
AddLanguage cs .cz .cs
AddLanguage da .dk
AddLanguage de .de
AddLanguage el .el
AddLanguage en .en
AddLanguage eo .eo
AddLanguage es .es
AddLanguage et .et
AddLanguage fr .fr
AddLanguage he .he
AddLanguage hr .hr
AddLanguage it .it
AddLanguage ja .ja
AddLanguage ko .ko
AddLanguage ltz .ltz
AddLanguage nl .nl
AddLanguage nn .nn
AddLanguage no .no
AddLanguage pl .po
AddLanguage pt .pt
AddLanguage pt-BR .pt-br
AddLanguage ru .ru
AddLanguage sv .sv
AddLanguage zh-CN .zh-cn
AddLanguage zh-TW .zh-tw
增加(需要重新启动Apache)
AddLanguage ja-jp .ja
AddLanguage en-us .en
追加示例
# curl -H 'Accept-Language: en-us, ja, en;q=0.8' localhost
Japanese contents
<-- Add httpd.conf 「AddLanguage en-us .en」-->
# service httpd restart
# curl -H 'Accept-Language: en-us, ja, en;q=0.8' localhost
English contents
※此设定也可以写在”.htaccess”文件中。