mod_substitute.html.en revision ac082aefa89416cbdc9a1836eaf3bed9698201c8
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" /><link rel="stylesheet" type="text/css" href="/style/css/prettify.css" />
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen<script src="/style/scripts/prettify.js" type="text/javascript">
10eed2803538d660048f6e733602e82a75ef6885noodl<link href="/images/favicon.ico" rel="shortcut icon" /></head>
d229f940abfb2490dee17979e9a5ff31b7012eb5rbowen<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>
10eed2803538d660048f6e733602e82a75ef6885noodl<div class="up"><a href="./"><img title="<-" alt="<-" src="/images/left.gif" /></a></div>
3f08db06526d6901aa08c110b5bc7dde6bc39905nd<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>
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung<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>
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 <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>
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh<ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
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<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 <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
2060bb0b7e53ae377492426fe35fe4d3cf5bf815jim take place on the boundary of this one. This is the default.</dd>
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>
e487d6c09669296f94a5190cc34586a98e624a00nd <div class="example"><h3>Example</h3><pre class="prettyprint lang-config">
a4784b5a082381b03e972caf3aa052a64c68f06dhumbedooh<Location />
a4784b5a082381b03e972caf3aa052a64c68f06dhumbedooh</Location>
10eed2803538d660048f6e733602e82a75ef6885noodl <p>If either the pattern or the substitution contain a slash
10eed2803538d660048f6e733602e82a75ef6885noodl character then an alternative delimiter should be used:</p>
e487d6c09669296f94a5190cc34586a98e624a00nd <div class="example"><h3>Example of using an alternate delimiter</h3><pre class="prettyprint lang-config">
a4784b5a082381b03e972caf3aa052a64c68f06dhumbedooh<Location />
a4784b5a082381b03e972caf3aa052a64c68f06dhumbedooh Substitute "s|<BR */?>|<br />|i"
a4784b5a082381b03e972caf3aa052a64c68f06dhumbedooh</Location>
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>
e487d6c09669296f94a5190cc34586a98e624a00nd <div class="example"><h3>Example of using backreferences and captures</h3><pre class="prettyprint lang-config">
a4784b5a082381b03e972caf3aa052a64c68f06dhumbedooh<Location />
a4784b5a082381b03e972caf3aa052a64c68f06dhumbedooh</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
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 <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>
e487d6c09669296f94a5190cc34586a98e624a00nd <div class="example"><h3>Rewriting URLs embedded in proxied content</h3><pre class="prettyprint lang-config">
a4784b5a082381b03e972caf3aa052a64c68f06dhumbedoohProxyPassReverse /blog/ http://internal.blog.example.com/
a4784b5a082381b03e972caf3aa052a64c68f06dhumbedoohSubstitute "s|http://internal.blog.example.com/|http://www.example.com/blog/|i"
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>
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung<p><span>Available Languages: </span><a href="/en/mod/mod_substitute.html" title="English"> en </a></p>
727872d18412fc021f03969b8641810d8896820bhumbedooh</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>Notice:</strong><br />This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div>
727872d18412fc021f03969b8641810d8896820bhumbedoohvar comments_shortname = 'httpd';
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedoohvar comments_identifier = 'http://httpd.apache.org/docs/trunk/mod/mod_substitute.html';
0d0ba3a410038e179b695446bb149cce6264e0abnd(function(w, d) {
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
727872d18412fc021f03969b8641810d8896820bhumbedooh d.write('<div id="comments_thread"><\/div>');
0d0ba3a410038e179b695446bb149cce6264e0abnd var s = d.createElement('script');
ac082aefa89416cbdc9a1836eaf3bed9698201c8humbedooh s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
0d0ba3a410038e179b695446bb149cce6264e0abnd (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
727872d18412fc021f03969b8641810d8896820bhumbedooh d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
0d0ba3a410038e179b695446bb149cce6264e0abnd})(window, document);
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>
d229f940abfb2490dee17979e9a5ff31b7012eb5rbowen<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[//><!--
0d0ba3a410038e179b695446bb149cce6264e0abndif (typeof(prettyPrint) !== 'undefined') {
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd prettyPrint();