This article describes how to enable data compression by configuring Apache's mod_deflate module in an .htaccess file.
You can use the Apache mod_deflate module to compress output from your web site that is sent to client browsers. Using data compression can reduce page load times and the amount of bandwidth your site uses.
To enable data compression with the mod_deflate module, use a text editor to edit the .htaccess file. The following sample configuration demonstrates one way to enable data compression by specifying file extensions:
<IfModule mod_deflate.c> <filesMatch "\.(js|css|html|php)$"> SetOutputFilter DEFLATE </filesMatch> </IfModule>
In this example, Apache compresses any file that has an extension of .js, .css, .html, or .php.
Alternatively, you can use MIME types to specify which files to compress. The following sample configuration demonstrates one way to do this:
In this example, Apache compresses any file that uses one of the MIME types referenced by the AddOutputFilterByType directive.
To disable data compression, you can delete the relevant lines in the .htaccess file, or comment them out by preceding each line with #.
For more information about the mod_deflate module, please visit http://httpd.apache.org/docs/2.2/mod/mod_deflate.html.