Apache no-gzip 适用于 Mozilla 中的特定内容类型

发布于 2024-10-18 23:43:02 字数 995 浏览 3 评论 0原文

如果请求来自 Mozilla 浏览器并且请求的内容使用 mime 类型 application/pdf,我需要设置 no-gzip 标志。这看起来应该是相当微不足道的,但我在找出正确的表达方式时遇到了一些麻烦。

我使用以下内容进行了浏览器检查:

BrowserMatch ^Mozilla moz

据我了解,如果浏览器是 Mozilla,该语句会将环境变量“moz”设置为 true。不过,在此之后,我遇到了一些麻烦。具体来说,我似乎无法找到一种方法来确定将要返回的内容类型。从查看 apache 环境变量列表来看,HTTP_ACCEPT 似乎相关,但我找不到用于检查的正确语法的引用。从我阅读的教程中,我假设类似以下内容:

%{HTTP_ACCEPT} application/pdf pdf

将“pdf”变量设置为 true,但 apache 服务器不会启动(强烈暗示这根本不正确)。 他认为存在一个名为 mime 的指令,该指令允许您检查内容类型:

mime application/pdf pdf

一位同事还提到, 指令甚至存在)。有人可以指出一些好的初学者资源,这些资源可以为我提供有关如何正确执行这些检查和引用变量的线索吗?我主要是在检查 apache 文档本身和他们的一些教程,但我一定遗漏了一些东西。

作为参考,我迄今为止一直在查看的文档:

http://httpd.apache .org/docs/current/env.html

http://httpd .apache.org/docs/current/howto/cgi.html

提前感谢您的帮助。

I need to set the no-gzip flag if a request is coming from the Mozilla browser and the content being requested uses the mime type application/pdf. This seems like it should be fairly trivial, but I'm having some trouble figuring out the proper way of expressing it.

I've got the browser check using the following:

BrowserMatch ^Mozilla moz

From what I understand, that statement will set the environment variable 'moz' to true if the browser is Mozilla. After this though, I'm having some trouble. Specifically, I can't seem to find a way to figure out the content-type that's going to be returned. From looking at a list of apache environment variables, HTTP_ACCEPT seemed related, but I can't find a reference to the proper syntax for checking. From tutorials that I read, I had assumed that something along the lines of:

%{HTTP_ACCEPT} application/pdf pdf

would set the 'pdf' variable to true, but the apache sever wouldn't start (giving the strong hint that that's not right at all). A coworker also mentioned that he'd thought a directive called mime exists, which allows you to check the content-type as:

mime application/pdf pdf

Similarly though, I couldn't get that to work either (and I can't find any reference to such a directive even existing). Could someone point out some good beginner resources that would give me a clue about how to perform these checks and reference variables properly? I've mostly been checking the apache documentation itself and some of their tutorials, but I must be missing something.

For reference, the documentation I've been looking at thus far:

http://httpd.apache.org/docs/current/env.html

http://httpd.apache.org/docs/current/howto/cgi.html

Thanks in advance for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏有森光若流苏 2024-10-25 23:43:02

你已经非常接近了,deflate 文档有一个示例配置,显示如何 gzip 特定文件或如何免除某些文件:

http://httpd.apache.org/docs/2.0/mod/mod_deflate.html

将 BrowserMatch 规则放入 FilesMatch 中,使其仅适用于 PDF。

http://httpd.apache.org/docs/2.0/mod/core .html#filesmatch

应该可以,祝你好运!

更新

从问题海报中获得更多信息后,似乎 mod_filter 应该能够组合用户代理(浏览器)和内容类型的条件。 (评论里讨论)

You're very close, the deflate documentation has a sample configuration that shows how to gzip specific files or how to exempt certain files:

http://httpd.apache.org/docs/2.0/mod/mod_deflate.html

Place the BrowserMatch rules in a FilesMatch to make them only apply to PDFs.

http://httpd.apache.org/docs/2.0/mod/core.html#filesmatch

That should work, good luck!

UPDATE

After some more information from the question poster it seems that mod_filter should be able to combine conditions for User-Agent (Browser) and Content-Type. (discussion in comments)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文