当Accept-Encoding是gzip或deflate时,Content-Encoding不会显示在Response头中

我正在使用Firefox,当我将Accept-Encoding设置为“deflate,gzip”时,我在响应头文件中得到了“Content-Encoding:gzip”。 当我使用Accempt-Encoding作为deflate或gzip时,“Content-Encoding”将从标题中删除。

任何人都可以请解释我为什么? 有没有我需要考虑的任何apacheconfiguration?

如果您正在提供.gz文件,也许您正在寻找在文件扩展名和所需的MIMEtypes与mod_mime之间添加关联。 以下内容可以添加到VirtualHostconfiguration中。

AddEncoding x-gzip .gz 

或者,用于提供预压缩内容的更完整示例不仅包括添加编码types,还包括禁用mod_deflate和重置内容types。 这个例子使用mod_header来添加编码types。

 <IfModule mod_headers.c> # Serve gzip compressed CSS files if they exist # and the client accepts gzip. RewriteCond "%{HTTP:Accept-encoding}" "gzip" RewriteCond "%{DOCUMENT_ROOT}%{REQUEST_FILENAME}\.gz" -s RewriteRule "^(.*)\.css" "$1\.css\.gz" [QSA] # Serve gzip compressed JS files if they exist # and the client accepts gzip. RewriteCond "%{HTTP:Accept-encoding}" "gzip" RewriteCond "%{DOCUMENT_ROOT}%{REQUEST_FILENAME}\.gz" -s RewriteRule "^(.*)\.js" "$1\.js\.gz" [QSA] # Serve correct content types, and prevent mod_deflate double gzip. RewriteRule "\.css\.gz$" "-" [T=text/css,E=no-gzip:1] RewriteRule "\.js\.gz$" "-" [T=text/javascript,E=no-gzip:1] <FilesMatch "(\.js\.gz|\.css\.gz)$"> # Serve correct encoding type. Header append Content-Encoding gzip # Force proxies to cache gzipped & # non-gzipped css/js files separately. Header append Vary Accept-Encoding </FilesMatch> </IfModule> 

(注意,上面的代码将DOCUMENT_ROOT添加到引用样本的RewriteCond文件path中,因为我认为在2.2+版本的VirtualHost环境中使用它时需要这样做。)

参考RFC,它提供了有关在Accept-Encoding中可以使用哪些值以及服务器如何根据Accept-Encoding字段使用这些规则testing内容编码是否可接受的详细信息,

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html