mod_substitute.html.en revision 3f08db06526d6901aa08c110b5bc7dde6bc39905
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<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>
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>
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen<div class="up"><a href="./"><img title="<-" alt="<-" src="/images/left.gif" /></a></div>
10eed2803538d660048f6e733602e82a75ef6885noodl<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.5</a> > <a href="./">Modules</a></div>
10eed2803538d660048f6e733602e82a75ef6885noodl<div id="preamble"><h1>Apache Module mod_substitute</h1>
10eed2803538d660048f6e733602e82a75ef6885noodl<p><span>Available Languages: </span><a href="/en/mod/mod_substitute.html" title="English"> en </a></p>
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 <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 id="quickview"><h3 class="directives">Directives</h3>
10eed2803538d660048f6e733602e82a75ef6885noodl<li><img alt="" src="/images/down.gif" /> <a href="#substitute">Substitute</a></li>
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<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>
7f0952c0239ea2d6e37b472db6fde4ef2718343dsf <p>The <code class="directive">Substitute</code> directive specifies a
10eed2803538d660048f6e733602e82a75ef6885noodl search and replace pattern to apply to the response body.</p>
10eed2803538d660048f6e733602e82a75ef6885noodl <p>The meaning of the pattern can be modified by using any
10eed2803538d660048f6e733602e82a75ef6885noodl combination of these flags:</p>
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 <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 <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 <Location />
4aa603e6448b99f9371397d439795c91a93637eand </Location>
10eed2803538d660048f6e733602e82a75ef6885noodl <p>If either the pattern or the substitution contain a slash
10eed2803538d660048f6e733602e82a75ef6885noodl character then an alternative delimiter should be used:</p>
4aa603e6448b99f9371397d439795c91a93637eand <div class="example"><h3>Example of using an alternate delimiter</h3><p><code>
a4784b5a082381b03e972caf3aa052a64c68f06dhumbedooh <Location />
e487d6c09669296f94a5190cc34586a98e624a00nd Substitute "s|<BR */?>|<br />|i"
4cb65c31bc681540ea623e1cb2bdd09749fb8d7esf </Location>
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 <Location />
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen </Location>
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>
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 <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 Substitute "s|http://internal.blog.example.com/|http://www.example.com/blog/|i"
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<p><span>Available Languages: </span><a href="/en/mod/mod_substitute.html" title="English"> en </a></p>
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>