How to enable GZip compression on Apache Server?
In a very simple language, GZip compress all the data and send to browser. All the latest browser understands and accept compressed files.
There are two major ways to enable the GZip Compression on the Apache Server web-sites.
1) Using httpd
You need to install mod_deflate module, if it is not installed than you can download it from Apache httpd Modules and add it to httpd modules directory on your server.
Once you add mod_deflate module in your httpd modules directory, you completed half work. Now open your “httpd.conf” file and search for “mod_deflate”. You will find the following line
LoadModule deflate_module modules/mod_deflate.so
If it is commented than uncomment it, so it will LoadModule directive for mod_deflate.
Now we need to create a Deflate Rule Set which tells your apache server that compress which types of file.
Create “httpd-deflate.conf” file and copy following code in that file
#Set GZip for all output SetOutputFilter DEFLATE #Not Include the below file types SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|iso|tar|bz2|sit|rar|png|jpg|gif|jpeg|flv|swf|mp3)$ no-gzip #Use compression Level DeflateCompressionLevel 9 #You can Handle browser specific compression using following rules BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch ^Mozilla/4.0 no-gzip BrowserMatch bMSIE !no-gzip !gzip-only-text/html SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
Now, open “httpd.conf” file and add following code
# Deflate configuration include <path of file>/httpd-deflate.conf
Now restart your Apache Server and its working GZip Compression. Your website will load 60% faster than before.
2) Using .htaccess file
You can add following code in your htaccess file
If above code is not working than you can try another code which is as below