0

I have deflate module enabled but when I put my code in .htaccess, it is not working. On various websites I have tested and it shows me to enable gzip compression. Below is the code for deflate:

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE text/javascript
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE image/x-icon
    AddOutputFilterByType DEFLATE image/svg+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/x-font
    AddOutputFilterByType DEFLATE application/x-font-truetype
    AddOutputFilterByType DEFLATE application/x-font-ttf
    AddOutputFilterByType DEFLATE application/x-font-otf
    AddOutputFilterByType DEFLATE application/x-font-opentype
    AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
    AddOutputFilterByType DEFLATE font/ttf
    AddOutputFilterByType DEFLATE font/otf
    AddOutputFilterByType DEFLATE font/opentype

    # For Olders Browsers Which Can't Handle Compression
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>

When I enable deflate in terminal, this is the message that I get:

sudo a2enmod deflate

Considering dependency filter for deflate:
Module filter already enabled
Module deflate already enabled

7
  • Try removing the <IfModule> wrapper. Add the HTTP response headers for say a CSS file to your question.
    – MrWhite
    Dec 12, 2016 at 8:52
  • Which version of apache are you using? If you use 2.4 you do not need to use the <IfModule> and </IfModule>
    – Orphans
    Dec 12, 2016 at 9:14
  • @Orphans Why does the Apache version determine whether you need the <IfModule> wrapper?
    – MrWhite
    Dec 12, 2016 at 9:20
  • @w3dk Apache 2.4 does not need it on some modules and on DEFLATE it is not needed.
    – Orphans
    Dec 12, 2016 at 10:01
  • @Orphans With regards to mod_deflate, that has nothing to do with the Apache version. The same would apply to Apache 2.2/2.0. The <IfModule> wrapper is arguably required here since you are also setting environment variables with mod_setenvif - and these should only be set if mod_deflate is enabled. Of course, if the system is only expected to function with mod_deflate enabled then remove the <IfModule> wrapper (it should fail with an error in such cases, rather than fail silently). mod_deflate is not a core module in any version of Apache - so this applies to all versions.
    – MrWhite
    Dec 12, 2016 at 10:25

0

You must log in to answer this question.

Browse other questions tagged .