500 error when compressing files with .htaccess
Solution 1
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?
Solution 2
After spending hours of search I found this article, thought someone else might find it helpful,
Enjoy.
Solution 3
## 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>
believe me
Doing Desktop Applications and Web Development, coming from a PHP background and ended up developing C# Applications with large data driven SQL/MySQL databases. Are you saying that its not possible to do what ever you're thinking of doing? Not for me! I will keep grabbing and searching knocking my head on the wall to get that thing done, although you saying its not possible to do I will get that.
Updated on June 03, 2022Comments
-
believe me almost 2 years
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?
-
believe me over 11 yearsThanks Nilpo, I'm not getting the error anymore, but I dont see it should get compressed when I try to check if its copmressed, so how can I improve thats really compressed?,
-
Nilpo over 11 yearsActually, if that resolved the error, you do not have the necessary module installed. You can test compression for a page here: whatsmyip.org/http-compression-test
-
believe me over 11 yearsOk, I test it in two sites, and its not gzipped, so I guess I need to install it?
-
Scott over 11 years@believeme Alternatively you can run
sudo a2enmod deflate
andsudo service apache2 restart
to load mod deflate -
believe me over 11 years@Nilpo Thank you very much, lets investigate it, and I'll let you know the results I got.
-
believe me over 11 years@Scott I dont have much knowlage in these two types you mentioned, but just curious to know if I need to instal that things or am I able to do that without installaitions?
-
Nilpo over 11 yearsmod_deflate is generally available in most PHP installations. Who is your hosting provider?
-
believe me over 11 years@Nilpo Siteground.com is my hosting provider
-
believe me over 11 yearsThanks alot @Nilpo I very appreciate your help, I'm looking into your post and let you know my results.
-
believe me over 11 years@Nilpo I actauly did these two things you mentioned in the last edit and it works perfectly, but I'm trying to do that in a .htaccess file so I dont have to put the php in each aditional file, so I'll try to figure how to do it with .htaccess what you mentioned in the first edit.
-
Nilpo over 11 yearsUnfortunately LoadModule only works within the context of the httpd.conf file. The reason being that modules are loaded when the Apache service is started, not each time a request is made which is when the .htaccess file is checked.
-
believe me over 11 years@Nilpo I see in the
phpinfo()
file that zip option is enabled, and also zlib is enabled, that means that mod_deflate is also anabled? -
Nilpo over 11 yearsThe zip extension adds support for zip files. The zlib extension is used for PHP compression. Neither is part of mod_deflate. The .htaccess check I gave you earlier is the easiest way to determine if it is loaded or not.
-
believe me over 11 years@Nilpo Now I got it, look at this article, the problem is that in some version you have to use
mod_deflate
, and some versions you have to usemod_gzip
, any ways, I very appreciate your help, I'll check you answer. -
Nilpo over 11 yearsCorrect. I believe in Apache 2.x, mod_deflate is preferred. Earlier versions use mod_gzip.
-
train about 10 yearsNote to anyone else having problems with this. I had to also enable "mod_filter" in addition to "mod_deflate". Cheers.
-
plamut over 8 yearsPlease edit your answer a bit, because it gives an impression of SCREAMING. Thanks! :)
-
Devner about 8 yearsI can confirm that indeed, uncommenting "mod_filter" can help fix the issue, as that is how I resolved mine.
-
R T almost 7 yearsI might add that mod_headers needs to be enabled too (magento)
-
kittygirl over 5 years@Nilpo,I commnet` #LoadModule filter_module modules/mod_filter.so`,but compression still work.what's the problem?