]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_substitute.xml
Update transformations.
[apache] / docs / manual / mod / mod_substitute.xml
1 <?xml version="1.0"?>
2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
5
6 <!--
7  Licensed to the Apache Software Foundation (ASF) under one or more
8  contributor license agreements.  See the NOTICE file distributed with
9  this work for additional information regarding copyright ownership.
10  The ASF licenses this file to You under the Apache License, Version 2.0
11  (the "License"); you may not use this file except in compliance with
12  the License.  You may obtain a copy of the License at
13
14      http://www.apache.org/licenses/LICENSE-2.0
15
16  Unless required by applicable law or agreed to in writing, software
17  distributed under the License is distributed on an "AS IS" BASIS,
18  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  See the License for the specific language governing permissions and
20  limitations under the License.
21 -->
22
23 <modulesynopsis metafile="mod_substitute.xml.meta">
24
25 <name>mod_substitute</name>
26 <description>Perform search and replace operations on response bodies</description>
27 <status>Experimental</status>
28 <sourcefile>mod_substitute.c</sourcefile>
29 <identifier>substitute_module</identifier>
30 <compatibility>Available in Apache HTTP Server 2.2.7 and later</compatibility>
31
32 <summary>
33     <p><module>mod_substitute</module> provides a mechanism to perform
34     both regular expression and fixed string substitutions on
35     response bodies.</p>
36 </summary>
37
38 <directivesynopsis>
39 <name>Substitute</name>
40 <description>Pattern to filter the response content</description>
41 <syntax>Substitute <var>s/pattern/substitution/[infq]</var></syntax>
42 <contextlist><context>directory</context>
43 <context>.htaccess</context></contextlist>
44 <override>FileInfo</override>
45
46 <usage>
47     <p>The <directive>Substitute</directive> directive specifies a
48     search and replace pattern to apply to the response body.</p>
49     
50     <p>The meaning of the pattern can be modified by using any
51     combination of these flags:</p>
52     
53     <dl>
54         <dt><code>i</code></dt>
55         <dd>Perform a case-insensitive match.</dd>
56         <dt><code>n</code></dt>
57         <dd>By default the pattern is treated as a regular expression.
58         Using the <code>n</code> flag forces the pattern to be treated
59         as a fixed string.</dd>
60         <dt><code>f</code></dt>
61         <dd>The <code>f</code> flag causes mod_substitute to flatten the
62         result of a substitution allowing for later substitutions to
63         take place on the boundary of this one. This is the default.</dd>
64         <dt><code>q</code></dt>
65         <dd>The <code>q</code> flag causes mod_substitute to not
66         flatten the buckets after each substitution. This can
67         result in much faster response and a decrease in memory
68         utilization, but should only be used if there is no possibility
69         that the result of one substitution will ever match a pattern
70         or regex of a subsequent one.</dd>
71     </dl>
72     
73     <example><title>Example</title>
74         &lt;Location /&gt;
75         <indent>
76             AddOutputFilterByType SUBSTITUTE text/html<br />
77             Substitute s/foo/bar/ni<br />
78         </indent>
79         &lt;/Location&gt;
80     </example>
81     
82     <p>If either the pattern or the substitution contain a slash
83     character then an alternative delimiter should be used:</p>
84     
85     <example><title>Example of using an alternate delimiter</title>
86         &lt;Location /&gt;
87         <indent>
88             AddOutputFilterByType SUBSTITUTE text/html<br />
89             Substitute "s|&lt;BR */?&gt;|&lt;br /&gt;|i"
90         </indent>
91         &lt;/Location&gt;
92     </example>
93
94     <p>A common use scenario for <code>mod_substitute</code> is the
95     situation in which a front-end server proxies requests to a back-end
96     server which returns HTML with hard-coded embedded URLs that refer
97     to the back-end server. These URLs don't work for the end-user,
98     since the back-end server is unreachable.</p>
99
100     <p>In this case, <code>mod_substutite</code> can be used to rewrite
101     those URLs into something that will work from the front end:</p>
102
103     <example><title>Rewriting URLs embedded in proxied content</title>
104     ProxyPass /blog/ http://internal.blog.example.com<br />
105     ProxyPassReverse /blog/ http://internal.blog.example.com/<br />
106     <br />
107     Substitute "s|http://internal.blog.example.com/|http://www.example.com/blog/|i"
108     </example>
109
110     <p><directive module="mod_proxy">ProxyPassReverse</directive>
111     modifies any <code>Location</code> (redirect) headers that are sent
112     by the back-end server, and, in this example,
113     <code>Substitute</code> takes care of the rest of the problem by
114     fixing up the HTML response as well.</p>
115
116 </usage>
117 </directivesynopsis>
118
119 </modulesynopsis>