mod_substitute.html.en revision 5effc8b39fae5cd169d17f342bfc265705840014
10eed2803538d660048f6e733602e82a75ef6885noodl<?xml version="1.0" encoding="ISO-8859-1"?>
10eed2803538d660048f6e733602e82a75ef6885noodl<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
10eed2803538d660048f6e733602e82a75ef6885noodl<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
10eed2803538d660048f6e733602e82a75ef6885noodl XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
10eed2803538d660048f6e733602e82a75ef6885noodl This file is generated from xml source: DO NOT EDIT
10eed2803538d660048f6e733602e82a75ef6885noodl XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
10eed2803538d660048f6e733602e82a75ef6885noodl -->
10eed2803538d660048f6e733602e82a75ef6885noodl<title>mod_substitute - Apache HTTP Server</title>
10eed2803538d660048f6e733602e82a75ef6885noodl<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
10eed2803538d660048f6e733602e82a75ef6885noodl<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
10eed2803538d660048f6e733602e82a75ef6885noodl<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
10eed2803538d660048f6e733602e82a75ef6885noodl<link href="/images/favicon.ico" rel="shortcut icon" /></head>
10eed2803538d660048f6e733602e82a75ef6885noodl<body>
10eed2803538d660048f6e733602e82a75ef6885noodl<div id="page-header">
10eed2803538d660048f6e733602e82a75ef6885noodl<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="/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>
10eed2803538d660048f6e733602e82a75ef6885noodl<img alt="" src="/images/feather.gif" /></div>
10eed2803538d660048f6e733602e82a75ef6885noodl<div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="/images/left.gif" /></a></div>
10eed2803538d660048f6e733602e82a75ef6885noodl<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>
10eed2803538d660048f6e733602e82a75ef6885noodl<div id="page-content">
10eed2803538d660048f6e733602e82a75ef6885noodl<div id="preamble"><h1>Apache Module mod_substitute</h1>
10eed2803538d660048f6e733602e82a75ef6885noodl<div class="toplang">
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung<p><span>Available Languages: </span><a href="/en/mod/mod_substitute.html" title="English">&nbsp;en&nbsp;</a></p>
10eed2803538d660048f6e733602e82a75ef6885noodl</div>
10eed2803538d660048f6e733602e82a75ef6885noodl<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>
7f0952c0239ea2d6e37b472db6fde4ef2718343dsf<tr><th><a href="module-dict.html#Status">Status:</a></th><td>Extension</td></tr>
10eed2803538d660048f6e733602e82a75ef6885noodl<tr><th><a href="module-dict.html#ModuleIdentifier">Module�Identifier:</a></th><td>substitute_module</td></tr>
46f74e65e6051e6e9391c8e17c5116317210facetakashi<tr><th><a href="module-dict.html#SourceFile">Source�File:</a></th><td>mod_substitute.c</td></tr>
2f46ce2a814d7f2b126dfb9f1b25fd64e2fbdc11rbowen<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>
10eed2803538d660048f6e733602e82a75ef6885noodl<h3>Summary</h3>
10eed2803538d660048f6e733602e82a75ef6885noodl
10eed2803538d660048f6e733602e82a75ef6885noodl <p><code class="module"><a href="/mod/mod_substitute.html">mod_substitute</a></code> provides a mechanism to perform
10eed2803538d660048f6e733602e82a75ef6885noodl both regular expression and fixed string substitutions on
10eed2803538d660048f6e733602e82a75ef6885noodl response bodies.</p>
10eed2803538d660048f6e733602e82a75ef6885noodl</div>
10eed2803538d660048f6e733602e82a75ef6885noodl<div id="quickview"><h3 class="directives">Directives</h3>
10eed2803538d660048f6e733602e82a75ef6885noodl<ul id="toc">
10eed2803538d660048f6e733602e82a75ef6885noodl<li><img alt="" src="/images/down.gif" /> <a href="#substitute">Substitute</a></li>
10eed2803538d660048f6e733602e82a75ef6885noodl</ul>
10eed2803538d660048f6e733602e82a75ef6885noodl</div>
10eed2803538d660048f6e733602e82a75ef6885noodl
10eed2803538d660048f6e733602e82a75ef6885noodl<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
10eed2803538d660048f6e733602e82a75ef6885noodl<div class="directive-section"><h2><a name="Substitute" id="Substitute">Substitute</a> <a name="substitute" id="substitute">Directive</a></h2>
10eed2803538d660048f6e733602e82a75ef6885noodl<table class="directive">
10eed2803538d660048f6e733602e82a75ef6885noodl<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Pattern to filter the response content</td></tr>
2060bb0b7e53ae377492426fe35fe4d3cf5bf815jim<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>Substitute <var>s/pattern/substitution/[infq]</var></code></td></tr>
10eed2803538d660048f6e733602e82a75ef6885noodl<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>directory, .htaccess</td></tr>
10eed2803538d660048f6e733602e82a75ef6885noodl<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
7f0952c0239ea2d6e37b472db6fde4ef2718343dsf<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
10eed2803538d660048f6e733602e82a75ef6885noodl<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_substitute</td></tr>
10eed2803538d660048f6e733602e82a75ef6885noodl</table>
10eed2803538d660048f6e733602e82a75ef6885noodl <p>The <code class="directive">Substitute</code> directive specifies a
10eed2803538d660048f6e733602e82a75ef6885noodl search and replace pattern to apply to the response body.</p>
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf
10eed2803538d660048f6e733602e82a75ef6885noodl <p>The meaning of the pattern can be modified by using any
10eed2803538d660048f6e733602e82a75ef6885noodl combination of these flags:</p>
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf
10eed2803538d660048f6e733602e82a75ef6885noodl <dl>
10eed2803538d660048f6e733602e82a75ef6885noodl <dt><code>i</code></dt>
10eed2803538d660048f6e733602e82a75ef6885noodl <dd>Perform a case-insensitive match.</dd>
10eed2803538d660048f6e733602e82a75ef6885noodl <dt><code>n</code></dt>
10eed2803538d660048f6e733602e82a75ef6885noodl <dd>By default the pattern is treated as a regular expression.
10eed2803538d660048f6e733602e82a75ef6885noodl Using the <code>n</code> flag forces the pattern to be treated
10eed2803538d660048f6e733602e82a75ef6885noodl as a fixed string.</dd>
10eed2803538d660048f6e733602e82a75ef6885noodl <dt><code>f</code></dt>
10eed2803538d660048f6e733602e82a75ef6885noodl <dd>The <code>f</code> flag causes mod_substitute to flatten the
10eed2803538d660048f6e733602e82a75ef6885noodl result of a substitution allowing for later substitutions to
2060bb0b7e53ae377492426fe35fe4d3cf5bf815jim take place on the boundary of this one. This is the default.</dd>
2060bb0b7e53ae377492426fe35fe4d3cf5bf815jim <dt><code>q</code></dt>
2060bb0b7e53ae377492426fe35fe4d3cf5bf815jim <dd>The <code>q</code> flag causes mod_substitute to not
2060bb0b7e53ae377492426fe35fe4d3cf5bf815jim flatten the buckets after each substitution. This can
2060bb0b7e53ae377492426fe35fe4d3cf5bf815jim result in much faster response and a decrease in memory
2060bb0b7e53ae377492426fe35fe4d3cf5bf815jim utilization, but should only be used if there is no possibility
2060bb0b7e53ae377492426fe35fe4d3cf5bf815jim that the result of one substitution will ever match a pattern
2060bb0b7e53ae377492426fe35fe4d3cf5bf815jim or regex of a subsequent one.</dd>
10eed2803538d660048f6e733602e82a75ef6885noodl </dl>
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf
10eed2803538d660048f6e733602e82a75ef6885noodl <div class="example"><h3>Example</h3><p><code>
10eed2803538d660048f6e733602e82a75ef6885noodl &lt;Location /&gt;
10eed2803538d660048f6e733602e82a75ef6885noodl <span class="indent">
10eed2803538d660048f6e733602e82a75ef6885noodl AddOutputFilterByType SUBSTITUTE text/html<br />
10eed2803538d660048f6e733602e82a75ef6885noodl Substitute s/foo/bar/ni<br />
10eed2803538d660048f6e733602e82a75ef6885noodl </span>
10eed2803538d660048f6e733602e82a75ef6885noodl &lt;/Location&gt;
10eed2803538d660048f6e733602e82a75ef6885noodl </code></p></div>
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf
10eed2803538d660048f6e733602e82a75ef6885noodl <p>If either the pattern or the substitution contain a slash
10eed2803538d660048f6e733602e82a75ef6885noodl character then an alternative delimiter should be used:</p>
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf
10eed2803538d660048f6e733602e82a75ef6885noodl <div class="example"><h3>Example of using an alternate delimiter</h3><p><code>
10eed2803538d660048f6e733602e82a75ef6885noodl &lt;Location /&gt;
10eed2803538d660048f6e733602e82a75ef6885noodl <span class="indent">
10eed2803538d660048f6e733602e82a75ef6885noodl AddOutputFilterByType SUBSTITUTE text/html<br />
10eed2803538d660048f6e733602e82a75ef6885noodl Substitute "s|&lt;BR */?&gt;|&lt;br /&gt;|i"
10eed2803538d660048f6e733602e82a75ef6885noodl </span>
10eed2803538d660048f6e733602e82a75ef6885noodl &lt;/Location&gt;
10eed2803538d660048f6e733602e82a75ef6885noodl </code></p></div>
10eed2803538d660048f6e733602e82a75ef6885noodl
4cb65c31bc681540ea623e1cb2bdd09749fb8d7esf <p>Backreferences can be used in the comparison and in the substitution,
206f0fb731ca7d2d2b2378cbd5b2882080490bd7covener when regular expressions are used, as illustrated in the following example: </p>
206f0fb731ca7d2d2b2378cbd5b2882080490bd7covener <div class="example"><h3>Example of using backreferences and captures</h3><p><code>
206f0fb731ca7d2d2b2378cbd5b2882080490bd7covener &lt;Location /&gt;
206f0fb731ca7d2d2b2378cbd5b2882080490bd7covener <span class="indent">
206f0fb731ca7d2d2b2378cbd5b2882080490bd7covener AddOutputFilterByType SUBSTITUTE text/html<br />
206f0fb731ca7d2d2b2378cbd5b2882080490bd7covener # "foo=k,bar=k" -&gt; "foo/bar=k" <br />
206f0fb731ca7d2d2b2378cbd5b2882080490bd7covener Substitute "s|foo=(\w+),bar=\1|foo/bar=$1"
206f0fb731ca7d2d2b2378cbd5b2882080490bd7covener </span>
206f0fb731ca7d2d2b2378cbd5b2882080490bd7covener &lt;/Location&gt;
206f0fb731ca7d2d2b2378cbd5b2882080490bd7covener </code></p></div>
206f0fb731ca7d2d2b2378cbd5b2882080490bd7covener
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen <p>A common use scenario for <code>mod_substitute</code> is the
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen situation in which a front-end server proxies requests to a back-end
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen server which returns HTML with hard-coded embedded URLs that refer
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen to the back-end server. These URLs don't work for the end-user,
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen since the back-end server is unreachable.</p>
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen <p>In this case, <code>mod_substutite</code> can be used to rewrite
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen those URLs into something that will work from the front end:</p>
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen <div class="example"><h3>Rewriting URLs embedded in proxied content</h3><p><code>
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen ProxyPass /blog/ http://internal.blog.example.com<br />
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen ProxyPassReverse /blog/ http://internal.blog.example.com/<br />
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen <br />
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen Substitute "s|http://internal.blog.example.com/|http://www.example.com/blog/|i"
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen </code></p></div>
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen <p><code class="directive"><a href="/mod/mod_proxy.html#proxypassreverse">ProxyPassReverse</a></code>
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen modifies any <code>Location</code> (redirect) headers that are sent
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen by the back-end server, and, in this example,
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen <code>Substitute</code> takes care of the rest of the problem by
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen fixing up the HTML response as well.</p>
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen
10eed2803538d660048f6e733602e82a75ef6885noodl</div>
10eed2803538d660048f6e733602e82a75ef6885noodl</div>
10eed2803538d660048f6e733602e82a75ef6885noodl<div class="bottomlang">
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung<p><span>Available Languages: </span><a href="/en/mod/mod_substitute.html" title="English">&nbsp;en&nbsp;</a></p>
10eed2803538d660048f6e733602e82a75ef6885noodl</div><div id="footer">
5effc8b39fae5cd169d17f342bfc265705840014rbowen<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>
10eed2803538d660048f6e733602e82a75ef6885noodl<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="/faq/">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p></div>
10eed2803538d660048f6e733602e82a75ef6885noodl</body></html>