mod_substitute.html.en revision 30471a4650391f57975f60bbb6e4a90be7b284bf
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<?xml version="1.0" encoding="ISO-8859-1"?>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd This file is generated from xml source: DO NOT EDIT
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd -->
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<title>mod_substitute - Apache HTTP Server</title>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen<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" />
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen<script src="/style/scripts/prettify.js" type="text/javascript">
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen</script>
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<link href="/images/favicon.ico" rel="shortcut icon" /></head>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<body>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<div id="page-header">
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen<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>
3f08db06526d6901aa08c110b5bc7dde6bc39905nd<p class="apache">Apache HTTP Server Version 2.5</p>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<img alt="" src="/images/feather.gif" /></div>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="/images/left.gif" /></a></div>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<div id="path">
3f08db06526d6901aa08c110b5bc7dde6bc39905nd<a href="http://www.apache.org/">Apache</a> &gt; <a href="http://httpd.apache.org/">HTTP Server</a> &gt; <a href="http://httpd.apache.org/docs/">Documentation</a> &gt; <a href="../">Version 2.5</a> &gt; <a href="./">Modules</a></div>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<div id="page-content">
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<div id="preamble"><h1>Apache Module mod_substitute</h1>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<div class="toplang">
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung<p><span>Available Languages: </span><a href="/en/mod/mod_substitute.html" title="English">&nbsp;en&nbsp;</a></p>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd</div>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Perform search and replace operations on response bodies</td></tr>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<tr><th><a href="module-dict.html#Status">Status:</a></th><td>Extension</td></tr>
f2dddcb17c7d7e94cc69563d3c99f9d035224ecctrawick<tr><th><a href="module-dict.html#ModuleIdentifier">Module�Identifier:</a></th><td>substitute_module</td></tr>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<tr><th><a href="module-dict.html#SourceFile">Source�File:</a></th><td>mod_substitute.c</td></tr>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<tr><th><a href="module-dict.html#Compatibility">Compatibility:</a></th><td>Available in Apache HTTP Server 2.2.7 and later</td></tr></table>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<h3>Summary</h3>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd <p><code class="module"><a href="/mod/mod_substitute.html">mod_substitute</a></code> provides a mechanism to perform
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd both regular expression and fixed string substitutions on
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd response bodies.</p>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd</div>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<div id="quickview"><h3 class="directives">Directives</h3>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<ul id="toc">
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<li><img alt="" src="/images/down.gif" /> <a href="#substitute">Substitute</a></li>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd</ul>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<div class="directive-section"><h2><a name="Substitute" id="Substitute">Substitute</a> <a name="substitute" id="substitute">Directive</a></h2>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<table class="directive">
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Pattern to filter the response content</td></tr>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>Substitute <var>s/pattern/substitution/[infq]</var></code></td></tr>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>directory, .htaccess</td></tr>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_substitute</td></tr>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd</table>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd <p>The <code class="directive">Substitute</code> directive specifies a
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd search and replace pattern to apply to the response body.</p>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd <p>The meaning of the pattern can be modified by using any
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd combination of these flags:</p>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd <dl>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd <dt><code>i</code></dt>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd <dd>Perform a case-insensitive match.</dd>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd <dt><code>n</code></dt>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd <dd>By default the pattern is treated as a regular expression.
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd Using the <code>n</code> flag forces the pattern to be treated
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd as a fixed string.</dd>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd <dt><code>f</code></dt>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd <dd>The <code>f</code> flag causes mod_substitute to flatten the
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd result of a substitution allowing for later substitutions to
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd take place on the boundary of this one. This is the default.</dd>
27a7b74f8c50bd6074b0c71fae9927a71fde5b3fjim <dt><code>q</code></dt>
60b985952fbefc0e3a43dfe6847a6bceee698b58jim <dd>The <code>q</code> flag causes mod_substitute to not
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd flatten the buckets after each substitution. This can
27a7b74f8c50bd6074b0c71fae9927a71fde5b3fjim result in much faster response and a decrease in memory
60b985952fbefc0e3a43dfe6847a6bceee698b58jim utilization, but should only be used if there is no possibility
27a7b74f8c50bd6074b0c71fae9927a71fde5b3fjim that the result of one substitution will ever match a pattern
27a7b74f8c50bd6074b0c71fae9927a71fde5b3fjim or regex of a subsequent one.</dd>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd </dl>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd <div class="example"><h3>Example</h3><pre class="prettyprint lang-config">
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd&lt;Location /&gt;
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd AddOutputFilterByType SUBSTITUTE text/html
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd Substitute s/foo/bar/ni
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd&lt;/Location&gt;
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh </pre>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd</div>
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd <p>If either the pattern or the substitution contain a slash
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung character then an alternative delimiter should be used:</p>
727872d18412fc021f03969b8641810d8896820bhumbedooh
0d0ba3a410038e179b695446bb149cce6264e0abnd <div class="example"><h3>Example of using an alternate delimiter</h3><pre class="prettyprint lang-config">
727872d18412fc021f03969b8641810d8896820bhumbedooh&lt;Location /&gt;
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh AddOutputFilterByType SUBSTITUTE text/html
0d0ba3a410038e179b695446bb149cce6264e0abnd Substitute "s|&lt;BR */?&gt;|&lt;br /&gt;|i"
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh&lt;/Location&gt;
727872d18412fc021f03969b8641810d8896820bhumbedooh </pre>
0d0ba3a410038e179b695446bb149cce6264e0abnd</div>
0d0ba3a410038e179b695446bb149cce6264e0abnd
0d0ba3a410038e179b695446bb149cce6264e0abnd <p>Backreferences can be used in the comparison and in the substitution,
ac082aefa89416cbdc9a1836eaf3bed9698201c8humbedooh when regular expressions are used, as illustrated in the following example: </p>
0d0ba3a410038e179b695446bb149cce6264e0abnd <div class="example"><h3>Example of using backreferences and captures</h3><pre class="prettyprint lang-config">
0d0ba3a410038e179b695446bb149cce6264e0abnd&lt;Location /&gt;
0d0ba3a410038e179b695446bb149cce6264e0abnd AddOutputFilterByType SUBSTITUTE text/html
727872d18412fc021f03969b8641810d8896820bhumbedooh # "foo=k,bar=k" -&gt; "foo/bar=k"
0d0ba3a410038e179b695446bb149cce6264e0abnd Substitute "s|foo=(\w+),bar=\1|foo/bar=$1"
0d0ba3a410038e179b695446bb149cce6264e0abnd&lt;/Location&gt;
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh </pre>
1a1356f375e36db7bee379ea0684ab389579f798rbowen</div>
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen
0d0ba3a410038e179b695446bb149cce6264e0abnd <p>A common use scenario for <code>mod_substitute</code> is the
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd situation in which a front-end server proxies requests to a back-end
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd server which returns HTML with hard-coded embedded URLs that refer
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd to the back-end server. These URLs don't work for the end-user,
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd 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>
<div class="example"><h3>Rewriting URLs embedded in proxied content</h3><pre class="prettyprint lang-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"
</pre>
</div>
<p><code class="directive"><a href="/mod/mod_proxy.html#proxypassreverse">ProxyPassReverse</a></code>
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>
</div>
</div>
<div class="bottomlang">
<p><span>Available Languages: </span><a href="/en/mod/mod_substitute.html" title="English">&nbsp;en&nbsp;</a></p>
</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>This section is experimental!</strong><br />Comments placed here should not be expected
to last beyond the testing phase of this system, nor do we in any way guarantee that we'll read them.</div><div id="disqus_thread" /><script type="text/javascript"><!--//--><![CDATA[//><!--
var lang = 'en';
var disqus_shortname = 'httpd';
var disqus_identifier = window.location.href.replace(/(current|trunk)/, "2.4").replace(/\/[a-z]{2}\//, "/").replace(window.location.protocol, "http:") + '.' + lang;
if (disqus_identifier.indexOf("httpd.apache.org") != -1) {
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = window.location.protocol + '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
} else {
var text = document.createTextNode("Comments have been disabled for offline viewing.");
document.getElementById('disqus_thread').appendChild(text);
}
//--><!]]></script></div><div id="footer">
<p class="apache">Copyright 2012 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>
<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[//><!--
if (typeof(prettyPrint) !== undefined) {
prettyPrint();
}
//--><!]]></script>
</body></html>