Apache > HTTP Server > Documentation > Version 2.2 > Modules

Please note

This document refers to a legacy release (2.2) of Apache httpd. The active release (2.4) is documented here. If you have not already upgraded, please follow this link for more information.

You may follow this link to go to the current version of this document.

Apache Module mod_substitute

Available Languages:  en 

Description:Perform search and replace operations on response bodies
Module Identifier:substitute_module
Source File:mod_substitute.c
Compatibility:Available in Apache 2.2.7 and later


mod_substitute provides a mechanism to perform both regular expression and fixed string substitutions on response bodies.



Substitute Directive

Description:Pattern to filter the response content
Syntax:Substitute s/pattern/substitution/[infq]
Context:directory, .htaccess

The Substitute directive specifies a search and replace pattern to apply to the response body.

The meaning of the pattern can be modified by using any combination of these flags:

Perform a case-insensitive match.
By default the pattern is treated as a regular expression. Using the n flag forces the pattern to be treated as a fixed string.
The f flag causes mod_substitute to flatten the result of a substitution allowing for later substitutions to take place on the boundary of this one. This is the default.
The q flag causes mod_substitute to not flatten the buckets after each substitution. This can result in much faster response and a decrease in memory utilization, but should only be used if there is no possibility that the result of one substitution will ever match a pattern or regex of a subsequent one.


<Location /> AddOutputFilterByType SUBSTITUTE text/html
Substitute s/foo/bar/ni

If either the pattern or the substitution contain a slash character then an alternative delimiter should be used:

Example of using an alternate delimiter

<Location /> AddOutputFilterByType SUBSTITUTE text/html
Substitute "s|<BR */?>|<br />|i"

Available Languages:  en 



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 mailing lists.