最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - 500 error when compressing files with .htaccess - Stack Overflow

programmeradmin2浏览0评论

I'm trying to compress files with .htaccess but I'm getting a 500 internal error,

This is the code I'm trying to use.

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

I've also tried this but getting the same error,

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

Any suggestions why?

I'm trying to compress files with .htaccess but I'm getting a 500 internal error,

This is the code I'm trying to use.

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

I've also tried this but getting the same error,

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

Any suggestions why?

Share Improve this question edited Jun 4, 2015 at 21:49 believe me asked Aug 29, 2012 at 16:33 believe mebelieve me 9081 gold badge5 silver badges24 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 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?

After spending hours of search I found this article, thought someone else might find it helpful,

Enjoy.

## DEFLATE ##

#mod_filter.so and mod_deflate.so

should be ON !!!!

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

This worked fine for me (paste in .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
发布评论

评论列表(0)

  1. 暂无评论