最近在对几个旧网站翻新时,发现这样一个问题:
原来的页面是使用 GBK,GB2312编码,当前的页面使用的是 UTF-8.
不管怎样设置 htnl 的 charset,用浏览器访问时,原来的页面一直乱码。浏览器不能识别页面指定的编码。
<meta http-equiv="Content-Type" content="text/html; charset=GBK" />
或
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
环境
CentOS release 6.7 (Final) 64bit
Apache httpd 2.2.15
问题的原因
由于apache httpd 的配置问题,默认是UTF-8,摘抄其中内容如下: /etc/httpd/conf/httpd.conf
#
# 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 UTF-8
重启httpd服务器即可。
#service httpd restart