1<?xml version="1.0" encoding="ISO-8859-1"?> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 3<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!-- 4 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 5 This file is generated from xml source: DO NOT EDIT 6 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 7 --> 8<title>Filters - Apache HTTP Server</title> 9<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" /> 10<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" /> 11<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="/style/css/prettify.css" /> 12<script src="/style/scripts/prettify.js" type="text/javascript"> 13</script> 14 15<link href="/images/favicon.ico" rel="shortcut icon" /></head> 16<body id="manual-page"><div id="page-header"> 17<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p> 18<p class="apache">Apache HTTP Server Version 2.2</p> 19<img alt="" src="/images/feather.gif" /></div> 20<div class="up"><a href="./"><img title="<-" alt="<-" src="/images/left.gif" /></a></div> 21<div id="path"> 22<a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="./">Version 2.2</a></div><div id="page-content"><div id="preamble"><h1>Filters</h1> 23<div class="toplang"> 24<p><span>Available Languages: </span><a href="/en/filter.html" title="English"> en </a> | 25<a href="/es/filter.html" hreflang="es" rel="alternate" title="Espa�ol"> es </a> | 26<a href="/fr/filter.html" hreflang="fr" rel="alternate" title="Fran�ais"> fr </a> | 27<a href="/ja/filter.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> | 28<a href="/ko/filter.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> | 29<a href="/tr/filter.html" hreflang="tr" rel="alternate" title="T�rk�e"> tr </a></p> 30</div> 31 32 <p>This document describes the use of filters in Apache.</p> 33 </div> 34<div id="quickview"><ul id="toc"><li><img alt="" src="/images/down.gif" /> <a href="#intro">Filtering in Apache 2</a></li> 35<li><img alt="" src="/images/down.gif" /> <a href="#smart">Smart Filtering</a></li> 36<li><img alt="" src="/images/down.gif" /> <a href="#using">Using Filters</a></li> 37</ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div> 38<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 39<div class="section"> 40<h2><a name="intro" id="intro">Filtering in Apache 2</a></h2> 41 42 <table class="related"><tr><th>Related Modules</th><th>Related Directives</th></tr><tr><td><ul><li><code class="module"><a href="/mod/mod_filter.html">mod_filter</a></code></li><li><code class="module"><a href="/mod/mod_deflate.html">mod_deflate</a></code></li><li><code class="module"><a href="/mod/mod_ext_filter.html">mod_ext_filter</a></code></li><li><code class="module"><a href="/mod/mod_include.html">mod_include</a></code></li><li><code class="module"><a href="/mod/mod_charset_lite.html">mod_charset_lite</a></code></li></ul></td><td><ul><li><code class="directive"><a href="/mod/mod_filter.html#filterchain">FilterChain</a></code></li><li><code class="directive"><a href="/mod/mod_filter.html#filterdeclare">FilterDeclare</a></code></li><li><code class="directive"><a href="/mod/mod_filter.html#filterprotocol">FilterProtocol</a></code></li><li><code class="directive"><a href="/mod/mod_filter.html#filterprovider">FilterProvider</a></code></li><li><code class="directive"><a href="/mod/mod_mime.html#addinputfilter">AddInputFilter</a></code></li><li><code class="directive"><a href="/mod/mod_mime.html#addoutputfilter">AddOutputFilter</a></code></li><li><code class="directive"><a href="/mod/mod_mime.html#removeinputfilter">RemoveInputFilter</a></code></li><li><code class="directive"><a href="/mod/mod_mime.html#removeoutputfilter">RemoveOutputFilter</a></code></li><li><code class="directive"><a href="/mod/mod_ext_filter.html#extfilterdefine">ExtFilterDefine</a></code></li><li><code class="directive"><a href="/mod/mod_ext_filter.html#extfilteroptions">ExtFilterOptions</a></code></li><li><code class="directive"><a href="/mod/core.html#setinputfilter">SetInputFilter</a></code></li><li><code class="directive"><a href="/mod/core.html#setoutputfilter">SetOutputFilter</a></code></li></ul></td></tr></table> 43 44<p>The Filter Chain is available in Apache 2.0 and higher, 45and enables applications to process incoming and outgoing data 46in a highly flexible and configurable manner, regardless of 47where the data comes from. We can pre-process incoming data, 48and post-process outgoing data, at will. This is basically 49independent of the traditional request processing phases.</p> 50<p class="figure"> 51<img src="images/filter_arch.png" width="569" height="392" alt="Filters can be chained, in a Data Axis orthogonal to request processing" /> 52</p> 53<p>Some examples of filtering in the standard Apache distribution are:</p> 54<ul> 55<li><code class="module"><a href="/mod/mod_include.html">mod_include</a></code>, implements server-side includes.</li> 56<li><code class="module"><a href="/mod/mod_ssl.html">mod_ssl</a></code>, implements SSL encryption (https).</li> 57<li><code class="module"><a href="/mod/mod_deflate.html">mod_deflate</a></code>, implements compression/decompression on the fly.</li> 58<li><code class="module"><a href="/mod/mod_charset_lite.html">mod_charset_lite</a></code>, transcodes between different character sets.</li> 59<li><code class="module"><a href="/mod/mod_ext_filter.html">mod_ext_filter</a></code>, runs an external program as a filter.</li> 60</ul> 61<p>Apache also uses a number of filters internally to perform 62functions like chunking and byte-range handling.</p> 63 64<p>A wider range of applications are implemented by third-party filter 65modules available from <a href="http://modules.apache.org/">modules.apache.org</a> and 66elsewhere. A few of these are:</p> 67 68<ul> 69<li>HTML and XML processing and rewriting</li> 70<li>XSLT transforms and XIncludes</li> 71<li>XML Namespace support</li> 72<li>File Upload handling and decoding of HTML Forms</li> 73<li>Image processing</li> 74<li>Protection of vulnerable applications such as PHP scripts</li> 75<li>Text search-and-replace editing</li> 76</ul> 77</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 78<div class="section"> 79<h2><a name="smart" id="smart">Smart Filtering</a></h2> 80 81<p class="figure"> 82<img src="images/mod_filter_new.png" width="423" height="331" alt="Smart filtering applies different filter providers according to the state of request processing" /> 83</p> 84<p><code class="module"><a href="/mod/mod_filter.html">mod_filter</a></code>, included in Apache 2.1 and later, 85enables the filter chain to be configured dynamically at run time. 86So for example you can set up a proxy to rewrite 87HTML with an HTML filter and JPEG images with a completely 88separate filter, despite the proxy having no prior information 89about what the origin server will send. This works by using a 90filter harness, that dispatches to different providers according 91to the actual contents at runtime. Any filter may be either 92inserted directly in the chain and run unconditionally, or 93used as a provider and inserted dynamically. For example,</p> 94<ul> 95<li>an HTML processing filter will only run if the content is 96text/html or application/xhtml+xml</li> 97<li>A compression filter will only run if the input is a 98compressible type and not already compressed</li> 99<li>A charset conversion filter will be inserted if a text 100document is not already in the desired charset</li> 101</ul> 102</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 103<div class="section"> 104<h2><a name="using" id="using">Using Filters</a></h2> 105 106<p>There are two ways to use filtering: Simple and Dynamic. 107In general, you should use one or the other; mixing them can 108have unexpected consequences (although simple Input filtering 109can be mixed freely with either simple or dynamic Output filtering).</p> 110<p>The Simple Way is the only way to configure input filters, and is 111sufficient for output filters where you need a static filter chain. 112Relevant directives are 113 <code class="directive"><a href="/mod/core.html#setinputfilter">SetInputFilter</a></code>, 114 <code class="directive"><a href="/mod/core.html#setoutputfilter">SetOutputFilter</a></code>, 115 <code class="directive"><a href="/mod/mod_mime.html#addinputfilter">AddInputFilter</a></code>, 116 <code class="directive"><a href="/mod/mod_mime.html#addoutputfilter">AddOutputFilter</a></code>, 117 <code class="directive"><a href="/mod/mod_mime.html#removeinputfilter">RemoveInputFilter</a></code>, and 118 <code class="directive"><a href="/mod/mod_mime.html#removeoutputfilter">RemoveOutputFilter</a></code>.</p> 119 120<p>The Dynamic Way enables both static and flexible, dynamic configuration 121of output filters, as discussed in the <code class="module"><a href="/mod/mod_filter.html">mod_filter</a></code> page. 122Relevant directives are 123 <code class="directive"><a href="/mod/mod_filter.html#filterchain">FilterChain</a></code>, 124 <code class="directive"><a href="/mod/mod_filter.html#filterdeclare">FilterDeclare</a></code>, and 125 <code class="directive"><a href="/mod/mod_filter.html#filterprovider">FilterProvider</a></code>.</p> 126 127<p>One further directive <code class="directive"><a href="/mod/core.html#addoutputfilterbytype">AddOutputFilterByType</a></code> is still supported, 128but may be problematic and is now deprecated. Use dynamic 129configuration instead.</p> 130 131 </div></div> 132<div class="bottomlang"> 133<p><span>Available Languages: </span><a href="/en/filter.html" title="English"> en </a> | 134<a href="/es/filter.html" hreflang="es" rel="alternate" title="Espa�ol"> es </a> | 135<a href="/fr/filter.html" hreflang="fr" rel="alternate" title="Fran�ais"> fr </a> | 136<a href="/ja/filter.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> | 137<a href="/ko/filter.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> | 138<a href="/tr/filter.html" hreflang="tr" rel="alternate" title="T�rk�e"> tr </a></p> 139</div><div class="top"><a href="#page-header"><img src="/images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div> 140<script type="text/javascript"><!--//--><![CDATA[//><!-- 141var comments_shortname = 'httpd'; 142var comments_identifier = 'http://httpd.apache.org/docs/2.2/filter.html'; 143(function(w, d) { 144 if (w.location.hostname.toLowerCase() == "httpd.apache.org") { 145 d.write('<div id="comments_thread"><\/div>'); 146 var s = d.createElement('script'); 147 s.type = 'text/javascript'; 148 s.async = true; 149 s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier; 150 (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s); 151 } 152 else { 153 d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>'); 154 } 155})(window, document); 156//--><!]]></script></div><div id="footer"> 157<p class="apache">Copyright 2013 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p> 158<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!-- 159if (typeof(prettyPrint) !== 'undefined') { 160 prettyPrint(); 161} 162//--><!]]></script> 163</body></html>