Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache AddOutputFilterByType is deprecated. How to rewrite using mod_filter?

Tags:

apache

AddOutputFilterByType is deprecated in Apache.

The documentation says that the same functionality is available using mod_filter.

I currently use

AddOutputFilterByType DEFLATE text/html

What is the equivalent using mod_filter?

like image 210
Ian Avatar asked Mar 08 '11 08:03

Ian


2 Answers

AddOutputFilterByType had severe limitations in httpd-2.2 so it was marked deprecated there. But in httpd-2.4 this directive was moved to filter_module, corrected and un-deprecated.

In apache 2.2 you should instead enable filter_module and deflate_module and use:

# Declare a "gzip" filter, it should run after all internal filters like PHP or SSI
FilterDeclare  gzip CONTENT_SET

# "gzip" filter can change "Content-Length", can not be used with range requests
FilterProtocol gzip change=yes;byteranges=no

# Enable "gzip" filter if "Content-Type" contains "text/html", "text/css" etc.
FilterProvider gzip DEFLATE resp=Content-Type $text/html
FilterProvider gzip DEFLATE resp=Content-Type $text/css
FilterProvider gzip DEFLATE resp=Content-Type $text/javascript
FilterProvider gzip DEFLATE resp=Content-Type $application/javascript
FilterProvider gzip DEFLATE resp=Content-Type $application/x-javascript

# Add "gzip" filter to the chain of filters
FilterChain    gzip

deflate_module would only serve compressed content to browsers that declare support for gzip encoding in request header.

like image 126
Tometzky Avatar answered Oct 14 '22 19:10

Tometzky


I'm using mod_filter for substituing instead of deflating, but the idea is the same. This is what worked for me (I'm doing reverse proxy and rewriting urls and links):

LoadModule substitute_module modules/mod_substitute.so
LoadModule filter_module modules/mod_filter.so

FilterDeclare MYFILTER
# syntax changed in Apache2.4  (see also  https://httpd.apache.org/docs/current/mod/mod_filter.html)  
FilterProvider MYFILTER SUBSTITUTE "%{Content_Type} = 'text/html'"
FilterProvider MYFILTER SUBSTITUTE "%{Content_Type} = 'text/xml'"
FilterProvider MYFILTER SUBSTITUTE "%{Content_Type} = 'application/javascript'"
FilterProvider MYFILTER SUBSTITUTE "%{Content_Type} = 'application/json'"

<Location /sial/> 
  ProxyPass        http://localhost:8300/
  ProxyPassReverse http://localhost:8300/
  ProxyPassReverseCookiePath / /sial/  
  FilterChain MYFILTER
  Substitute "s|/tea_sial_v2|/sial/tea_sial_v2|inq"
</Location>
like image 44
Atila Avatar answered Oct 14 '22 20:10

Atila