- Overview
- Installation & Uninstallation
- Local and remote management using IIS 7
- Context and processing order
- Apache compatibility
- Modules
- core functions
- mod_antibot
- mod_asis
- mod_auth_basic
- mod_auth_digest
- mod_authn_anon
- mod_authn_dbd
- mod_authn_default
- mod_authn_file
- mod_authz_default
- mod_authz_groupfile
- mod_authz_host
- mod_authz_user
- mod_cache
- mod_dbd
- mod_deflate
- mod_developer
- mod_dir
- mod_disk_cache
- mod_env
- mod_evasive
- mod_expires
- mod_filter
- mod_gzip
- mod_headers
- mod_hotlink
- mod_linkfreeze
- mod_log_config
- mod_logio
- mod_mem_cache
- mod_mime
- mod_proxy
- mod_replace
- mod_rewrite
- mod_seo
- mod_setenvif
- mod_so
- mod_speling
- mod_usertrack
- mod_xsendfile
- Articles
- Release history
- Troubleshooting
- License agreement
mod_replace
Overview
mod_replace module allows to replace text strings based on regular expressions. It is generally used together with mod_proxy module to sanitize ill-behaving web-servers/applications (e.g. absolute links on web pages, absolute links in HTTP headers which aren't controlled by mod_proxy).
WARNING: Built in IIS compression should be disabled in order for content replacement function to work. You are free to enable compression using Ape's mod_gzip module.
Quick start
Related articles and topics
Enviroment variables
Name | Context | Description |
---|---|---|
mod_replace | S V D .h | set this environment variable to value with name of defined filter |
content-type | S V D .h | allows to explicitly specify the charset value for Content-Type header to be used by mod_replace |
Examples
This is how you can enable
simple_filter
filter
ReplaceFilterDefine simple_filter
ReplacePattern simple_filter "aaaa" "bbbb"
ReplacePattern simple_filter "cccc" "dddd"
SetEnv mod_replace simple_filter
Note!
Sometimes you'll need to explicitly specify the charset for mod_replace to use as some applications
(like PHP) reset it bypassing IIS leaving Ape modules ignorant. To override
Charset
parameter value
of
Content-Type
header use the following
SetEnv
line:
# sets Charset for mod_replace
SetEnv content-type windows-1251
Exact names of charsets may be taken from here .
Directives
Name | Context | Description |
---|---|---|
ReplaceFilterDefine | S V D .h | defines the name and parameters of the new filter |
ReplacePattern | S V D .h | configures match and replace patterns for the filter using regular expressions |
HeaderReplacePattern | S V D .h | configures regular-expressions-based match and replace patterns for the filter to alter response headers |
ReplaceFilterDefine
ReplaceFilterDefine directive is used to specify the name and parameters of the filter.
Syntax
ReplaceFilterDefine name [options ...]
- name - the name of the filter - is used to distinguish it from other filters.
-
options
- defines some filter characteristics:
- CaseIgnore - makes match pattern case-insensitive. If the options is not specified, comparison will be case-sensitive;
- intype=<mime> - limits pattern matching to specific MIME-type only.
Example
#process text/html only
ReplaceFilterDefine revproxy CaseIgnore intype=text/html
ReplacePattern revproxy "(http|https)://origin.server/" "\1://revproxy/"
SetEnv mod_replace revproxy
Example
#process all responses with Case
ReplaceFilterDefine revproxy
ReplacePattern revproxy "(http|https)://origin.server/" "\1://revproxy/"
SetEnv mod_replace revproxy
ReplacePattern
ReplacePattern directive specifies the match pattern and replacement string for the name filter.
Syntax
ReplacePattern name pattern string
- name - the name of the filter specified in ReplaceFilterDefine directive.
- pattern - a regular expression against which the HTTP body coming from the server will be matched.
- string - a replacement string that will be used if the pattern matches.
Example
#process text/html only
ReplaceFilterDefine revproxy CaseIgnore intype=text/html
ReplacePattern revproxy "(http|https)://origin.server/" "\1://revproxy/"
SetEnv mod_replace revproxy
HeaderReplacePattern
HeaderReplacePattern directive specifies the match pattern and replacement string for the name filter to edit HTTP response header .
Syntax
HeaderReplacePattern name header pattern string
- name - the name of the filter specified in ReplaceFilterDefine directive.
- header - the name of HTTP response header to be edited.
- pattern - a regular expression against which the HTTP body coming from the server will be matched.
- string - a replacement string that will be used if the pattern matches.
Example
ReplaceFilterDefine revproxy CaseIgnore intype=text/html
HeaderReplacePattern revproxy Set-Cookie "domain=server.com" "domain=revproxy.com"
Note!
To activate
HeaderReplacePattern
and
RequestHeaderPattern
filters
SetOutputFilter
is not necessary.
RequestHeaderPattern
RequestHeaderPattern directive specifies the match pattern and replacement string for the name filter to edit HTTP request header .
Syntax
RequestHeaderPattern header pattern string
- header - the name of HTTP request header to be edited.
- pattern - a regular expression against which the HTTP body coming from the server will be matched.
- string - a replacement string that will be used if the pattern matches.
Example
RequestHeaderPattern Cookie " UID=0815" " UID=007"
Note!
To activate
HeaderReplacePattern
and
RequestHeaderPattern
filters
SetOutputFilter
is not necessary.