How to Enable Gzip Compression for WordPress via .htaccess file?

When Gzip compression isn't enabled on WordPress website, Google PageSpeed Insight gives you a warning to Enable Compression. There are a couple ways you can fix this warning. The first, and one of the easiest is by using a caching plugin that supports enabling Gzip.

You can enable Enable HTTP (gzip) compression through caching plugin like W3 Total Cache or specific compression plugin like GZip Ninja Speed Compression. As an alternate way, you can enable Gzip compression is by editing your .htaccess file.

  1. Log into your cPanel.

  2. Under Files section, select File Manager menu.

  3. cPanel will popup a message asking you where you would like land within your website directories. In the same window, you will see the checkbox asking if you would like to show hidden files. Check the checkbox Show Hidden Files and click Go.

  4. Under public_html folder of your website, find and edit the file called .htaccess.

  5. Paste the following code into .htaccess file at the end of your existing content.

    <IfModule mod_deflate.c>
    # Compress HTML, CSS, JavaScript, Text, XML and fonts
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
    AddOutputFilterByType DEFLATE application/x-font
    AddOutputFilterByType DEFLATE application/x-font-opentype
    AddOutputFilterByType DEFLATE application/x-font-otf
    AddOutputFilterByType DEFLATE application/x-font-truetype
    AddOutputFilterByType DEFLATE application/x-font-ttf
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE font/opentype
    AddOutputFilterByType DEFLATE font/otf
    AddOutputFilterByType DEFLATE font/ttf
    AddOutputFilterByType DEFLATE image/svg+xml
    AddOutputFilterByType DEFLATE image/x-icon
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/javascript
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/xml
    
    # Removing browser bugs for older browsers
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    Header append Vary User-Agent
    </IfModule>

    Add Code in .htaccess File to Enable GZIP Compression

  6.  Save the changes.


Slowness issue with your WordPress site? Don't sweat it! Check out the 10 Effective and Easy Ways to Speed up WordPress Site.


  • 1 Users Found This Useful

Was this answer helpful?

Related Articles

How to Migrate / Transfer WordPress Website from WordPress.com to AccuWeb Hosting?

To transfer your WordPress.com website to a self-hosted WordPress website, first you will need a...

How to change the Site URL and Home URL Settings in WordPress?

WordPress offers two configurable URLs namely WordPress address and Site address to load the...

How to optimize your website on cPanel?

Please refer to the below steps to optimize your website in cPanel. Login to your cPanel...

How to change the WordPress dashboard language?

When you install the WordPress default language will be English. You can change it from the admin...

How to Deactivate Wordpress Plugins from phpMyAdmin and using FTP When Not Able to Access WP-Admin?

While doing troubleshooting for any of the websites, you might be suggested to deactivate all the...