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