mod_substitute.html.en revision 3f08db06526d6901aa08c110b5bc7dde6bc39905
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 -->
96ad5d81ee4a2cc66a4ae19893efc8aa6d06fae7jailletc<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" />
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
2e545ce2450a9953665f701bb05350f0d3f26275nd<link href="/images/favicon.ico" rel="shortcut icon" /></head>
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen<body>
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen<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>
10eed2803538d660048f6e733602e82a75ef6885noodl<p class="apache">Apache HTTP Server Version 2.5</p>
10eed2803538d660048f6e733602e82a75ef6885noodl<img alt="" src="/images/feather.gif" /></div>
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen<div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="/images/left.gif" /></a></div>
3f08db06526d6901aa08c110b5bc7dde6bc39905nd<div id="path">
10eed2803538d660048f6e733602e82a75ef6885noodl<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>
3f08db06526d6901aa08c110b5bc7dde6bc39905nd<div class="toplang">
10eed2803538d660048f6e733602e82a75ef6885noodl<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>
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung<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>
10eed2803538d660048f6e733602e82a75ef6885noodl<tr><th><a href="module-dict.html#SourceFile">Source�File:</a></th><td>mod_substitute.c</td></tr>
7f0952c0239ea2d6e37b472db6fde4ef2718343dsf<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>
b09fcdfc59ada4712150e7bcc7b502bb9e4601d8rjung
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>
2eb7a8afc318286c210a1fbb2ff2ba904471956frjung
10eed2803538d660048f6e733602e82a75ef6885noodl<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh<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>
10eed2803538d660048f6e733602e82a75ef6885noodl<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>
2060bb0b7e53ae377492426fe35fe4d3cf5bf815jim<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>
7f0952c0239ea2d6e37b472db6fde4ef2718343dsf <p>The <code class="directive">Substitute</code> directive specifies a
10eed2803538d660048f6e733602e82a75ef6885noodl search and replace pattern to apply to the response body.</p>
10eed2803538d660048f6e733602e82a75ef6885noodl
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>
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf <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
10eed2803538d660048f6e733602e82a75ef6885noodl take place on the boundary of this one. This is the default.</dd>
10eed2803538d660048f6e733602e82a75ef6885noodl <dt><code>q</code></dt>
10eed2803538d660048f6e733602e82a75ef6885noodl <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>
2060bb0b7e53ae377492426fe35fe4d3cf5bf815jim </dl>
2060bb0b7e53ae377492426fe35fe4d3cf5bf815jim
2060bb0b7e53ae377492426fe35fe4d3cf5bf815jim <div class="example"><h3>Example</h3><p><code>
10eed2803538d660048f6e733602e82a75ef6885noodl &lt;Location /&gt;
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf <span class="indent">
4aa603e6448b99f9371397d439795c91a93637eand AddOutputFilterByType SUBSTITUTE text/html<br />
a4784b5a082381b03e972caf3aa052a64c68f06dhumbedooh Substitute s/foo/bar/ni<br />
a4784b5a082381b03e972caf3aa052a64c68f06dhumbedooh </span>
4aa603e6448b99f9371397d439795c91a93637eand &lt;/Location&gt;
e487d6c09669296f94a5190cc34586a98e624a00nd </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
4aa603e6448b99f9371397d439795c91a93637eand <div class="example"><h3>Example of using an alternate delimiter</h3><p><code>
a4784b5a082381b03e972caf3aa052a64c68f06dhumbedooh &lt;Location /&gt;
a4784b5a082381b03e972caf3aa052a64c68f06dhumbedooh <span class="indent">
4aa603e6448b99f9371397d439795c91a93637eand AddOutputFilterByType SUBSTITUTE text/html<br />
e487d6c09669296f94a5190cc34586a98e624a00nd Substitute "s|&lt;BR */?&gt;|&lt;br /&gt;|i"
10eed2803538d660048f6e733602e82a75ef6885noodl </span>
4cb65c31bc681540ea623e1cb2bdd09749fb8d7esf &lt;/Location&gt;
206f0fb731ca7d2d2b2378cbd5b2882080490bd7covener </code></p></div>
4aa603e6448b99f9371397d439795c91a93637eand
a4784b5a082381b03e972caf3aa052a64c68f06dhumbedooh <p>Backreferences can be used in the comparison and in the substitution,
a4784b5a082381b03e972caf3aa052a64c68f06dhumbedooh when regular expressions are used, as illustrated in the following example: </p>
a4784b5a082381b03e972caf3aa052a64c68f06dhumbedooh <div class="example"><h3>Example of using backreferences and captures</h3><p><code>
4aa603e6448b99f9371397d439795c91a93637eand &lt;Location /&gt;
e487d6c09669296f94a5190cc34586a98e624a00nd <span class="indent">
206f0fb731ca7d2d2b2378cbd5b2882080490bd7covener AddOutputFilterByType SUBSTITUTE text/html<br />
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen # "foo=k,bar=k" -&gt; "foo/bar=k" <br />
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen Substitute "s|foo=(\w+),bar=\1|foo/bar=$1"
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen </span>
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen &lt;/Location&gt;
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen </code></p></div>
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen
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
4aa603e6448b99f9371397d439795c91a93637eand to the back-end server. These URLs don't work for the end-user,
a4784b5a082381b03e972caf3aa052a64c68f06dhumbedooh since the back-end server is unreachable.</p>
a4784b5a082381b03e972caf3aa052a64c68f06dhumbedooh
4aa603e6448b99f9371397d439795c91a93637eand <p>In this case, <code>mod_substutite</code> can be used to rewrite
e487d6c09669296f94a5190cc34586a98e624a00nd 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
2eb7a8afc318286c210a1fbb2ff2ba904471956frjung <p><code class="directive"><a href="/mod/mod_proxy.html#proxypassreverse">ProxyPassReverse</a></code>
2eb7a8afc318286c210a1fbb2ff2ba904471956frjung modifies any <code>Location</code> (redirect) headers that are sent
2eb7a8afc318286c210a1fbb2ff2ba904471956frjung by the back-end server, and, in this example,
2eb7a8afc318286c210a1fbb2ff2ba904471956frjung <code>Substitute</code> takes care of the rest of the problem by
2eb7a8afc318286c210a1fbb2ff2ba904471956frjung fixing up the HTML response as well.</p>
2eb7a8afc318286c210a1fbb2ff2ba904471956frjung
2eb7a8afc318286c210a1fbb2ff2ba904471956frjung
2eb7a8afc318286c210a1fbb2ff2ba904471956frjung</div>
2eb7a8afc318286c210a1fbb2ff2ba904471956frjung</div>
2eb7a8afc318286c210a1fbb2ff2ba904471956frjung<div class="bottomlang">
2eb7a8afc318286c210a1fbb2ff2ba904471956frjung<p><span>Available Languages: </span><a href="/en/mod/mod_substitute.html" title="English">&nbsp;en&nbsp;</a></p>
0d747e805cfc207e1b210904a3f4dd95f176b562jailletc</div><div id="footer">
2eb7a8afc318286c210a1fbb2ff2ba904471956frjung<p class="apache">Copyright 2011 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>
2eb7a8afc318286c210a1fbb2ff2ba904471956frjung<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>
2eb7a8afc318286c210a1fbb2ff2ba904471956frjung</body></html>