.htaccess mod_filter text/html gzip on apache 2.4

1k Views Asked by At

I'm trying to enable compression for Content-Type:text/html

I am running apache 2.4 and I found out that mod_gzip and mod_deflate are no longer used, but instead I should use mod_filter

https://httpd.apache.org/docs/2.4/mod/mod_filter.html

After a long google session and a lot of try / fail attempts decided to try my luck here.

I can confirm that both mod_filter and mod_deflate are enabled.

Combinations I tried to add to my .htaccess:

<IfModule mod_filter.c>
 AddOutputFilterByType DEFLATE text/html
</IfModule>

<IfModule mod_deflate.c>
    <IfModule mod_setenvif.c>
        <IfModule mod_headers.c>
            SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
            RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
        </IfModule>
    </IfModule>

    <IfModule mod_filter.c>
        AddOutputFilterByType DEFLATE text/html
    </IfModule>
</IfModule>

<IfModule filter_module>
FilterDeclare   COMPRESS
FilterProvider  COMPRESS  DEFLATE "%{Content_Type} = 'text/html'"
FilterChain     COMPRESS  
FilterProtocol  COMPRESS  DEFLATE change=yes;byteranges=no
</IfModule>

and basically anything I could find on the internet. But nothing works.

I keep getting the same result:

Request Headers: Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8 Accept-Encoding:gzip, deflate, sdch

Response Headers: Content-Type:text/html; charset=utf-8 (without the Content-Encoding:gzip header)

Using aws ec2 instance.

Found a workaround using httpd.conf. I'll just leave this here if anyone finds it useful.

And just to confirm - AddOutputFilterByType DEFLATE ... works on apache 2.4.

0

There are 0 best solutions below