apache - 为什么我的 Markdown 文件没有被压缩?

标签 apache .htaccess gzip markdown

我的 .htaccess 文件中有这个:

# gzip compression
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript application/json
</ifmodule>

这可确保给定的内容类型经过 gzip 压缩。

现场演示: http://ecmazing.com/js/index.js (在浏览器的开发工具中打开“Net”面板,然后查看响应 header )

enter image description here

但是我的 Markdown 文件没有被 gzip 压缩。

现场演示: http://ecmazing.com/data.md

enter image description here

如您所见,文件的内容类型为 text/plain,它位于我的 .htaccess 文件的内容类型列表中。那么,为什么不应用GZIP呢?

最佳答案

我猜你的 Markdown 文件没有通过 AddType 指令主动分配内容类型 text/plain - 因此服务器可能会将该内容类型发送为默认值,但 AddOutputFilterByType 不会自动将这些文件识别为该内容类型。

http://httpd.apache.org/docs/2.2/en/mod/core.html#addoutputfilterbytype证实了这一点,并说道:

“Enabling filters with AddOutputFilterByType may fail partially or completely in some cases. For example, no filters are applied if the MIME-type could not be determined and falls back to the DefaultType setting, even if the DefaultType is the same.”

因此,请使用 AddOutputFilter deflate md,或者尝试使用 AddType text/plain md.md 与内容类型显式关联。

关于apache - 为什么我的 Markdown 文件没有被压缩?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15499041/

相关文章:

regex - 在 mod_rewrite 规则正则表达式中匹配问号

java - 如何在 Mac OS X 上安装 mod_jk

javascript - 如何将所有 JS、CSS、IMG 重写为静态子域?

compression - 不推荐使用 GNU GZIP 环境变量,如何通过 tar 控制 ZLIB 压缩?

Gzip 的 JavaScript 实现

php - ubuntu 16 上 php7 出现 Apache2 错误

apache - 自定义 URI 方案的类似 HTTP 处理,可能吗?

.htaccess - RewriteRule htaccess 如果文件存在

apache - 针对特定浏览器/操作系统组合的 .htaccess 重写

Java 压缩大文件