冰与火之歌 发表于 2015-9-6 09:27:45

linux乱码解决

最近打算建立一个分享资源的网络空间,想使用FTP,但是又觉得不算好用。于是就直接使用Apache的Indexes参数来搭建一个可浏览目录的虚拟主 机,好处在于可以直接在浏览器中以网页形式展现。

      但是按照Apache的文档来配置就出现问题了。经过测试,如果目录中含有中文文件或者中文目录的时候,在IE下显示乱码,于是在浏览器中查看其编码发 现它默认使用ISO-8859-1编码,手动选择GB2312后就能正常显示。看来是Apache Indexes在处理中文的时候的编码不正确。

      仔细研究其说明文档,其中介绍,可以在Apache配置文件中为Indexes指定特定的编码,我们能够修改配置文件让其支持中文。具体办法如下:

      在配置文件中添加:

   IndexOptions Charset=GB2312

    这样这样就能解决Apache autoindex模块中文乱码问题了。


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

http://tilt.lib.tsinghua.edu.cn/node/528

Apache 2下如何设置文件目录列表的编码
Submitted by admin on Thu, 12/03/2009 - 21:11
Web
来源地址: http://httpd.apache.org/docs/2.0/mod/mod_autoindex.html
IndexOptions Directive
Description: Various configuration settings for directory indexing
Syntax: IndexOptions [+|-]option [[+|-]option] ...
Context: server config, virtual host, directory, .htaccess
Override: Indexes
Status: Base
Module: mod_autoindex

The IndexOptions directive specifies the behavior of the directory indexing. Option can be one of

Charset=character-set (Apache 2.0.61 and later)
The Charset keyword allows you to specify the character set of the generated page. The default is either ISO-8859-1 or UTF-8, depending on whether the underlying file system is unicode or not.
Example:
IndexOptions Charset=UTF-8

Apache 2默认使用ISO-8859-1或UTF-8编码。上传的文档目录和文件名称则使用了GBK编码字符,导致每次需要手工选择编码之后,才能正确显示其列出 的目录和文件名列表。为了设置以GBK编码显示目录和文件名列表,可以在Apache 2中设置上述选项:
IndexOptions Charset=GBK


++++++++++++++++++++++++++++++++++++++++++++++++++++++


使用IndexOptions FancyIndexing选项,
当访问没有DirectoryIndex指定文档的目录时,启用该选项可以针对目录下不同类型的文档指定相对应的icon
示例如下:
编辑httpd.conf,把下列代码放于任意位置:
IndexOptions FancyIndexing AddIcon /other/icons/exe.gif .bin .exe AddIcon /other/icons/dir.gif ^^DIRECTORY^^ AddIcon /other/icons/txt.gif .txt .php .PHP AddIcon /other/icons/html.gif .htm .html AddIcon /other/icons/image.gif .gif .jpg .bmp .png
重启apache
页: [1]
查看完整版本: linux乱码解决