mod_substitute.xml revision 643ed38ed1c7634b7306f1eb1058e1ce8c543686
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore<?xml version="1.0"?>
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore<!DOCTYPE modulesynopsis SYSTEM "/style/modulesynopsis.dtd">
6b5e5868e7ebf1aff3a5abd7d0c4ef0e5fbf3648Garrett D'Amore<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore<!-- $LastChangedRevision$ -->
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore<!--
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore Licensed to the Apache Software Foundation (ASF) under one or more
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore contributor license agreements. See the NOTICE file distributed with
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore this work for additional information regarding copyright ownership.
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore The ASF licenses this file to You under the Apache License, Version 2.0
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore (the "License"); you may not use this file except in compliance with
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore the License. You may obtain a copy of the License at
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore http://www.apache.org/licenses/LICENSE-2.0
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore Unless required by applicable law or agreed to in writing, software
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore distributed under the License is distributed on an "AS IS" BASIS,
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore See the License for the specific language governing permissions and
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore limitations under the License.
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore-->
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore<modulesynopsis metafile="mod_substitute.xml.meta">
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore<name>mod_substitute</name>
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore<description>Perform search and replace operations on response bodies</description>
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore<status>Extension</status>
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore<sourcefile>mod_substitute.c</sourcefile>
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore<identifier>substitute_module</identifier>
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore<summary>
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore <p><module>mod_substitute</module> provides a mechanism to perform
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore both regular expression and fixed string substitutions on
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore response bodies.</p>
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore</summary>
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore<directivesynopsis>
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore<name>Substitute</name>
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore<description>Pattern to filter the response content</description>
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore<syntax>Substitute <var>s/pattern/substitution/[infq]</var></syntax>
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore<contextlist><context>directory</context>
aa64fa16549f13233681f4b40e50fb5b1c18a97cGarrett D'Amore<context>.htaccess</context></contextlist>
aa64fa16549f13233681f4b40e50fb5b1c18a97cGarrett D'Amore<override>FileInfo</override>
aa64fa16549f13233681f4b40e50fb5b1c18a97cGarrett D'Amore
aa64fa16549f13233681f4b40e50fb5b1c18a97cGarrett D'Amore<usage>
aa64fa16549f13233681f4b40e50fb5b1c18a97cGarrett D'Amore <p>The <directive>Substitute</directive> directive specifies a
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore search and replace pattern to apply to the response body.</p>
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore <p>The meaning of the pattern can be modified by using any
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore combination of these flags:</p>
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore <dl>
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore <dt><code>i</code></dt>
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore <dd>Perform a case-insensitive match.</dd>
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore <dt><code>n</code></dt>
<dd>By default the pattern is treated as a regular expression.
Using the <code>n</code> flag forces the pattern to be treated
as a fixed string.</dd>
<dt><code>f</code></dt>
<dd>The <code>f</code> flag causes mod_substitute to flatten the
result of a substitution allowing for later substitutions to
take place on the boundary of this one. This is the default.</dd>
<dt><code>q</code></dt>
<dd>The <code>q</code> flag causes mod_substitute to not
flatten the buckets after each substitution. This can
result in much faster response and a decrease in memory
utilization, but should only be used if there is no possibility
that the result of one substitution will ever match a pattern
or regex of a subsequent one.</dd>
</dl>
<example><title>Example</title>
<highlight language="config">
&lt;Location /&gt;
AddOutputFilterByType SUBSTITUTE text/html
Substitute s/foo/bar/ni
&lt;/Location&gt;
</highlight>
</example>
<p>If either the pattern or the substitution contain a slash
character then an alternative delimiter should be used:</p>
<example><title>Example of using an alternate delimiter</title>
<highlight language="config">
&lt;Location /&gt;
AddOutputFilterByType SUBSTITUTE text/html
Substitute "s|&lt;BR */?&gt;|&lt;br /&gt;|i"
&lt;/Location&gt;
</highlight>
</example>
<p>Backreferences can be used in the comparison and in the substitution,
when regular expressions are used, as illustrated in the following example: </p>
<example><title>Example of using backreferences and captures</title>
<highlight language="config">
&lt;Location /&gt;
AddOutputFilterByType SUBSTITUTE text/html
# "foo=k,bar=k" -> "foo/bar=k"
Substitute "s|foo=(\w+),bar=\1|foo/bar=$1"
&lt;/Location&gt;
</highlight>
</example>
<p>A common use scenario for <code>mod_substitute</code> is the
situation in which a front-end server proxies requests to a back-end
server which returns HTML with hard-coded embedded URLs that refer
to the back-end server. These URLs don't work for the end-user,
since the back-end server is unreachable.</p>
<p>In this case, <code>mod_substutite</code> can be used to rewrite
those URLs into something that will work from the front end:</p>
<example><title>Rewriting URLs embedded in proxied content</title>
<highlight language="config">
ProxyPass /blog/ http://internal.blog.example.com
ProxyPassReverse /blog/ http://internal.blog.example.com/
Substitute "s|http://internal.blog.example.com/|http://www.example.com/blog/|i"
</highlight>
</example>
<p><directive module="mod_proxy">ProxyPassReverse</directive>
modifies any <code>Location</code> (redirect) headers that are sent
by the back-end server, and, in this example,
<code>Substitute</code> takes care of the rest of the problem by
fixing up the HTML response as well.</p>
</usage>
</directivesynopsis>
<directivesynopsis>
<name>SubstituteMaxLineLength</name>
<description>Set the maximum line size</description>
<syntax>SubstituteMaxLineLength <var>bytes</var>(b|B|k|K|m|M|g|G)</syntax>
<default>SubstituteMaxLineLength 1m</default>
<contextlist><context>directory</context>
<context>.htaccess</context></contextlist>
<override>FileInfo</override>
<compatibility>Available in httpd 2.5-dev and later</compatibility>
<usage>
<p>The maximum line size handled by <module>mod_substitute</module>
is limited to restrict memory use. The limit can be configured
using <directive>SubstituteMaxLineLength</directive>.
The value can be given as the number of bytes and can be suffixed
with a single letter <code>b</code>, <code>B</code>, <code>k</code>,
<code>K</code>, <code>m</code>, <code>M</code>, <code>g</code>,
<code>G</code> to provide the size in bytes, kilobytes, megabytes
or gigabytes respectively.</p>
<example><title>Example</title>
<highlight language="config">
&lt;Location /&gt;
AddOutputFilterByType SUBSTITUTE text/html
SubstituteMaxLineLength 10m
Substitute s/foo/bar/ni
&lt;/Location&gt;
</highlight>
</example>
</usage>
</directivesynopsis>
</modulesynopsis>