好吧,在Django上测试挺好的GBK编码的静态文件,部署到Apache后乱码了,默认编码变成了UTF-8,可是meta中明明指定了charset为GBK的:
<meta http-equiv="Content-Type" content="text/html; charset=GBK" />
由于中间只是把Django部署到Apache这一个变化,所以立即想到了Apache可能对编码做了转换。
打开httpd.conf,查找UTF-8,立即证实了自己的判断,相关配置项如下:
#
# Specify a default charset for all content served; this enables
# interpretation of all content as UTF-8 by default. To use the
# default browser choice (ISO-8859-1), or to allow the META tags
# in HTML content to override this choice, comment out this
# directive:
#
AddDefaultCharset UTF-8
按照注释的说明,我们把AddDefaultCharset comment了,默认编码就恢复GBK了。