Linux设置同时支持GBK(GB2312)和UTF-8编码
Apache中决定服务器编码的httpd.conf中AddDefaultCharset决定的,我设置为AddDefaultCharset utf-8,因此服务器默认是utf-8的;
AddDefaultCharset 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:
大概意思是:指定一个默认的字符集传送内容;这将所有内容默认以utf-8编码解析。
假设要使用浏览器默认选择(ISO-8859-1),或允许使用HTML的META来自动选择浏览器编码,注释掉这行即可。
那就是改为#AddDefaultCharset utf-8,这样此行不再起作用,浏览器将根据网页的META来选择字符编码,apache就可以支持多字符编码了。
具体操作:
SSH登陆后 vi /etc/httpd/conf/httpd.conf
输入/ 进入搜索状态,输入AddDefaultCharset 回车查找到需要的那行(29行左右),再输入i 进入编辑模式,在 AddDefaultCharset 之前插入# 注释掉,然后ctrl+c 退出编辑模式,再Caps Lock进入大写模式,连按两下ZZ退出到SSH命令行,最后重启apache, service httpd restart生效。
页:
[1]