c3aaccf2d58cbd445efed832c4028787ac9f1542noodl<!DOCTYPE modulesynopsis SYSTEM "/style/modulesynopsis.dtd">
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl<!-- $LastChangedRevision$ -->
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl Licensed to the Apache Software Foundation (ASF) under one or more
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl contributor license agreements. See the NOTICE file distributed with
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl this work for additional information regarding copyright ownership.
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl The ASF licenses this file to You under the Apache License, Version 2.0
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl (the "License"); you may not use this file except in compliance with
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl the License. You may obtain a copy of the License at
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl Unless required by applicable law or agreed to in writing, software
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl distributed under the License is distributed on an "AS IS" BASIS,
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl See the License for the specific language governing permissions and
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl limitations under the License.
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl<description>Perform search and replace operations on response bodies</description>
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl <p><module>mod_substitute</module> provides a mechanism to perform
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl both regular expression and fixed string substitutions on
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl response bodies.</p>
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl<directivesynopsis>
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl<description>Pattern to filter the response content</description>
ca33b922ae8ad1b24a8235b656b0ac6f82915355jim<syntax>Substitute <var>s/pattern/substitution/[infq]</var></syntax>
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl <p>The <directive>Substitute</directive> directive specifies a
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl search and replace pattern to apply to the response body.</p>
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl <p>The meaning of the pattern can be modified by using any
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl combination of these flags:</p>
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl <dd>By default the pattern is treated as a regular expression.
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl Using the <code>n</code> flag forces the pattern to be treated
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl as a fixed string.</dd>
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl <dd>The <code>f</code> flag causes mod_substitute to flatten the
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl result of a substitution allowing for later substitutions to
ca33b922ae8ad1b24a8235b656b0ac6f82915355jim take place on the boundary of this one. This is the default.</dd>
ca33b922ae8ad1b24a8235b656b0ac6f82915355jim <dd>The <code>q</code> flag causes mod_substitute to not
ca33b922ae8ad1b24a8235b656b0ac6f82915355jim flatten the buckets after each substitution. This can
ca33b922ae8ad1b24a8235b656b0ac6f82915355jim result in much faster response and a decrease in memory
ca33b922ae8ad1b24a8235b656b0ac6f82915355jim utilization, but should only be used if there is no possibility
ca33b922ae8ad1b24a8235b656b0ac6f82915355jim that the result of one substitution will ever match a pattern
ca33b922ae8ad1b24a8235b656b0ac6f82915355jim or regex of a subsequent one.</dd>
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar<Location "/">
ab152dac543de24fadd7ed0159c9f380af02061bhumbedooh</Location>
ab152dac543de24fadd7ed0159c9f380af02061bhumbedooh </highlight>
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl <p>If either the pattern or the substitution contain a slash
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl character then an alternative delimiter should be used:</p>
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl <example><title>Example of using an alternate delimiter</title>
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar<Location "/">
ab152dac543de24fadd7ed0159c9f380af02061bhumbedooh Substitute "s|<BR */?>|<br />|i"
ab152dac543de24fadd7ed0159c9f380af02061bhumbedooh</Location>
ab152dac543de24fadd7ed0159c9f380af02061bhumbedooh </highlight>
18ee8bb3db5cc3b04291f89301bd5d14dc271066lgentis <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>
206f0fb731ca7d2d2b2378cbd5b2882080490bd7covener <example><title>Example of using backreferences and captures</title>
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar<Location "/">
ab152dac543de24fadd7ed0159c9f380af02061bhumbedooh</Location>
ab152dac543de24fadd7ed0159c9f380af02061bhumbedooh </highlight>
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>
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen <example><title>Rewriting URLs embedded in proxied content</title>
2fae9d127f7143fabe8f73958eb9bde31df17d41coarProxyPass "/blog/" "http://internal.blog.example.com"
2fae9d127f7143fabe8f73958eb9bde31df17d41coarProxyPassReverse "/blog/" "http://internal.blog.example.com/"
ab152dac543de24fadd7ed0159c9f380af02061bhumbedoohSubstitute "s|http://internal.blog.example.com/|http://www.example.com/blog/|i"
ab152dac543de24fadd7ed0159c9f380af02061bhumbedooh </highlight>
f97b24463c41ab08129805bc63069b59c3ee0b48rbowen <p><directive module="mod_proxy">ProxyPassReverse</directive>
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>
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl</directivesynopsis>
643ed38ed1c7634b7306f1eb1058e1ce8c543686rjung<directivesynopsis>
643ed38ed1c7634b7306f1eb1058e1ce8c543686rjung<syntax>SubstituteMaxLineLength <var>bytes</var>(b|B|k|K|m|M|g|G)</syntax>
0d747e805cfc207e1b210904a3f4dd95f176b562jailletc<compatibility>Available in httpd 2.4.11 and later</compatibility>
643ed38ed1c7634b7306f1eb1058e1ce8c543686rjung <p>The maximum line size handled by <module>mod_substitute</module>
643ed38ed1c7634b7306f1eb1058e1ce8c543686rjung is limited to restrict memory use. The limit can be configured
643ed38ed1c7634b7306f1eb1058e1ce8c543686rjung The value can be given as the number of bytes and can be suffixed
643ed38ed1c7634b7306f1eb1058e1ce8c543686rjung with a single letter <code>b</code>, <code>B</code>, <code>k</code>,
643ed38ed1c7634b7306f1eb1058e1ce8c543686rjung <code>K</code>, <code>m</code>, <code>M</code>, <code>g</code>,
643ed38ed1c7634b7306f1eb1058e1ce8c543686rjung <code>G</code> to provide the size in bytes, kilobytes, megabytes
643ed38ed1c7634b7306f1eb1058e1ce8c543686rjung or gigabytes respectively.</p>
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar<Location "/">
643ed38ed1c7634b7306f1eb1058e1ce8c543686rjung SubstituteMaxLineLength 10m
643ed38ed1c7634b7306f1eb1058e1ce8c543686rjung</Location>
643ed38ed1c7634b7306f1eb1058e1ce8c543686rjung </highlight>
643ed38ed1c7634b7306f1eb1058e1ce8c543686rjung</directivesynopsis>
c3aaccf2d58cbd445efed832c4028787ac9f1542noodl</modulesynopsis>