How to change the default encoding to UTF

I am using a hosting company and it will list the files in a directory if the file index.html is not there ,it uses iso-8859-1 as the default encoding.

If the server is Apache, is there a way to set UTF-8 as the default instead?

Update: Additionally I found out that it is actually using a DOCTYPE of HTML 3.2 and then there is not charset at all... so it is not setting any encoding. But is there a way to change it to use UTF-8?


在httpd.conf中添加(或者如果它已经存在,则更改):

AddDefaultCharset utf-8

Add this to your .htaccess :

IndexOptions +Charset=UTF-8

Or, if you have administrator rights, you could set it globally by editing httpd.conf and adding:

AddDefaultCharset UTF-8

(You can use AddDefaultCharset in .htaccess too, but it won't affect Apache-generated directory listings that way.)


See AddDefaultCharset Directive, AddCharset Directive, and this article.

AddDefaultCharset utf-8

But I have to use Chinese characters now and then. Previously, I translated Chinese characters to Unicode code and include it in the document using the &# hack. But it is only useful for page having a few characters.

There is a better way to do that: encode the charset information in the filename, and apache will output the proper encoding header based on that. This is possible thanks to the AddCharset lines in the conf file, such as the line below:

conf/httpd.conf :

AddCharset UTF-8 .utf8

So if you have a file whose names ends in .html.utf8 , apache will serve the page as if it is encoded in UTF-8 and will dump the proper character-encoding directive in the header accordingly.

链接地址: http://www.djcxy.com/p/25124.html

上一篇: 为什么斯堪的纳维亚字符转换为UTF

下一篇: 如何将默认编码更改为UTF