16

我正在尝试使用 .htaccess 压缩文件,但出现 500 内部错误,

这是我正在尝试使用的代码。

# JavaScript compression htaccess ruleset
AddHandler application/x-httpd-php .js
php_value auto_prepend_file gzip-js.php
php_flag zlib.output_compression On

我也试过这个但得到同样的错误,

<files *.html>
SetOutputFilter DEFLATE
</files>

任何建议为什么?

4

4 回答 4

31

Do you have mod_deflate installed? Try this instead and see if your error goes away.

<ifModule mod_deflate.c>
<Files *.html>
SetOutputFilter DEFLATE
</Files>
</ifModule>

If this resolves the 500 error, then you probably don't have mod_deflate installed. You can test it by visiting HTTP Compression Test.

If you have access, you may be able to enable it by uncommenting the following lines in your httpd.conf file.

LoadModule filter_module modules/mod_filter.so
LoadModule deflate_module modules/mod_deflate.so

Then you will need to add an output type for each file type you wish to compress.

AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

As mentioned in the comments, AddOutputFilterByType depends on mod_filter. If you still get a 500 error you should check that this module is loaded too.

You can read more here: Use mod_deflate to Compress Web Content delivered by Apache

I can't find any documentation that suggests whether Siteground supports mod_deflate or not. Their KB suggests using gZip from PHP.

How to enable gZIP compression for your pages?
How to compress my CSS with gZIP?

于 2012-08-29T16:58:08.340 回答
4

经过数小时的搜索,我找到了这篇文章,认为其他人可能会觉得它有帮助,

享受。

于 2012-08-30T13:08:18.737 回答
2

##放气##

#mod_filter.so 和 mod_deflate.so

应该开启!!!!

<ifmodule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</ifmodule>
于 2015-10-08T02:47:13.197 回答
0

这对我来说很好(粘贴.htaccess):

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
于 2017-04-02T13:03:15.483 回答