gpt4 book ai didi

php - 我可以告诉 mod_deflate 和 PHP 只跳过对一个目录的压缩吗?

转载 作者:可可西里 更新时间:2023-11-01 13:01:37 25 4
gpt4 key购买 nike

为了压缩我的所有网页,我使用了这个 .htaccess 代码。它使用 Apache deflate如果可能,模块,否则应用 PHP ob_gzhandler压缩。

一切正常,但由于特定原因,我不想对文件夹 ./folderWithoutCompression 应用压缩.

问题:如何在 Apache deflate 的情况下添加此异常?在下面的脚本中是否定义了模块(PHP ob_gzhandler 案例)?

<IfModule mod_deflate.c>
# force deflate for mangled headers
# developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
</IfModule>
</IfModule>

# HTML, TXT, CSS, JavaScript, JSON, XML, HTC:
<IfModule filter_module>
FilterDeclare COMPRESS
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/html
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/css
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/plain
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/x-component
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/javascript
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/json
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xhtml+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/rss+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/atom+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/vnd.ms-fontobject
FilterProvider COMPRESS DEFLATE resp=Content-Type $image/svg+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/x-font-ttf
FilterProvider COMPRESS DEFLATE resp=Content-Type $font/opentype
FilterChain COMPRESS
FilterProtocol COMPRESS DEFLATE change=yes;byteranges=no
</IfModule>

<IfModule !mod_filter.c>
# Legacy versions of Apache
AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml
AddOutputFilterByType DEFLATE application/atom+xml
AddOutputFilterByType DEFLATE image/svg+xml application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font-ttf font/opentype
</IfModule>
</IfModule>

<IfModule !mod_deflate.c>
#Apache deflate module is not defined, active the page compression through PHP ob_gzhandler
php_flag output_buffering On
php_value output_handler ob_gzhandler
</IfModule>

编辑

作为解决方法,我使用自定义 content-type对于我的 folderWithoutCompression 文件夹中存在的所有文件。

我确信可以使用 <Location> 排除某些目录, <LocationMatch > , <DirectoryMatch > <Directory > ,但是当我尝试处理时,我总是得到 Apache 错误 500

最佳答案

我终于在这里找到了答案:

How to disable mod_deflate in apache2?

感谢@Gumbo

# for URL paths that begin with "/foo/bar/"
SetEnvIf Request_URI ^/foo/bar/ no-gzip=1

# for files that end with ".py"
<FilesMatch \.py$>
SetEnv no-gzip 1
</FilesMatch>

关于php - 我可以告诉 mod_deflate 和 PHP 只跳过对一个目录的压缩吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14171176/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com