From: Rich Bowen
+The RewriteMap
directive may not be used in
+<Directory> sections or .htaccess
files. You must
+declare the map in server or virtualhost context. You may use the map,
+once created, in your RewriteRule
and
+RewriteCond
directives in those scopes. You just can't
+declare it in those scopes.
+
The sections that follow describe the various MapTypes that may be used, and give examples of each.
@@ -170,6 +181,15 @@ telephone 328 +
+ The looked-up keys are cached by httpd until the mtime
+ (modified time) of the mapfile changes, or the httpd server is
+ restarted. This ensures better performance on maps that are called
+ by many requests.
+
mapfile.map.dir
and mapfiile.map.pag
. This is
normal, and you need only use the base name mapfile.map
in
your RewriteMap
directive.
+
+The looked-up keys are cached by httpd until the mtime
+(modified time) of the mapfile changes, or the httpd server is
+restarted. This ensures better performance on maps that are called
+by many requests.
+
RewriteMap
directive.
MapType: prg
, MapSource: Unix filesystem path to valid regular file
Here the source is a program, not a map file. To
-create it you can use a language of your choice, but
-the result has to be an executable program (either
-object-code or a script with the magic cookie trick
-'#!/path/to/interpreter
' as the first
-line).
This program is started once, when the Apache httpd server
-is started, and then communicates with the rewriting engine
-via its stdin
and stdout
-file-handles. For each map-function lookup it will
-receive the key to lookup as a newline-terminated string
-on stdin
. It then has to give back the
-looked-up value as a newline-terminated string on
-stdout
or the four-character string
-``NULL
'' if it fails (i.e., there
-is no corresponding value for the given key).
This feature utilizes the rewrite-map
mutex,
-which is required for reliable communication with the program.
-The mutex mechanism and lock file can be configured with the
-Mutex
directive.
External rewriting programs are not started if they're defined in a
-context that does not have RewriteEngine
set to
-on
A trivial program which will implement a 1:1 map (i.e., - key == value) could be:
-#!/usr/bin/perl -$| = 1; -while (<STDIN>) { - # ...put here any transformations or lookups... - print $_; -} -
But be very careful:
stdout
. Avoid this, as it will cause a deadloop!
-``$|=1
'' is used above, to prevent this.When a MapType of prg
is used, the MapSource is a
+ filesystem path to an executable program which will providing the
+ mapping behavior. This can be a compiled binary file, or a program
+ in an interpreted language such as Perl or Python.
This program is started once, when the Apache HTTP Server is
+ started, and then communicates with the rewriting engine via
+ STDIN
and STDOUT
. That is, for each map
+ function lookup, it expects one argument via STDIN
, and
+ should return one new-line terminated response string on
+ STDOUT
. If there is no corresponding lookup value, the
+ map program should return the four-character string
+ "NULL
" to indicate this.
External rewriting programs are not started if they're defined in
+ a context that does not have RewriteEngine
set to
+ on
.
This feature utilizes the rewrite-map
mutex,
+ which is required for reliable communication with the program.
+ The mutex mechanism and lock file can be configured with the
+ Mutex
directive.
A simple example is shown here which will replace all dashes with + underscores in a request URI.
+ +
+ RewriteMap d2u prg:/www/bin/dash2under.pl
+ RewriteRule - ${d2u:%{REQUEST_URI}}
+
+ #!/usr/bin/perl
+ $| = 1; # Turn off I/O buffering
+ while (<STDIN>) {
+
+ s/-/_/g; # Replace dashes with underscores
+ print $_;
+
+ }
+
$| = 1;
This will
+of course vary in other languages. Buffered I/O will cause httpd to wait
+for the output, and so it will hang.MapType: dbd
or fastdbd
,
-MapSource: An SQL SELECT statement that takes a single
- argument and returns a single value.
This uses mod_dbd
to implement a rewritemap
-by lookup in an SQL database. There are two forms:
-fastdbd
caches database lookups internally,
-dbd
doesn't. So dbd
incurs a
-performance penalty but responds immediately if the database
-contents are updated, while fastdbd
is more
-efficient but won't re-read database contents until server
-restart.
When a MapType of dbd
or fastdbd
is
+ used, the MapSource is a SQL SELECT statement that takes a single
+ argument and returns a single value.
mod_dbd
will need to be configured to point at
+ the right database for this statement to be executed.
There are two forms of this MapType.
+ Using a MapType of dbd
causes the query to be
+ executed with each map request, while using fastdbd
+ caches the database lookups internally. So, while
+ fastdbd
is more efficient, and therefore faster, it
+ won't pick up on changes to the database until the server is
+ restarted.
If a query returns more than one row, a random row from the result set is used.
+
RewriteMap myquery "fastdbd:SELECT destination FROM rewrite WHERE source = %s"
-
The RewriteMap
directive can occur more than
- once. For each mapping-function use one
- RewriteMap
directive to declare its rewriting
- mapfile. While you cannot declare a map in
- per-directory context it is of course possible to
- use this map in per-directory context.
mtime
of the
-mapfile changes or the server does a restart. This way you can have
-map-functions in rules which are used for every
-request. This is no problem, because the external lookup only happens
-once!
-RewriteMap
directive to declare its rewriting
+ mapfile.
+
+ While you cannot declare a map in
+ per-directory context (.htaccess
files or
+ <Directory> blocks) it is possible to
+ use this map in per-directory context.
Available Languages: en
diff --git a/docs/manual/rewrite/rewritemap.xml b/docs/manual/rewrite/rewritemap.xml index 119ae676ee..de53017cf2 100644 --- a/docs/manual/rewrite/rewritemap.xml +++ b/docs/manual/rewrite/rewritemap.xml @@ -102,6 +102,17 @@ in the map: RewriteRule ^/ex/(.*) ${examplemap:$1|/not_found.html} +
+The RewriteMap
directive may not be used in
+<Directory> sections or .htaccess
files. You must
+declare the map in server or virtualhost context. You may use the map,
+once created, in your RewriteRule
and
+RewriteCond
directives in those scopes. You just can't
+declare it in those scopes.
+
The sections that follow describe the various MapTypes that may be used, and give examples of each.
@@ -171,6 +182,15 @@ telephone 328 +
+ The looked-up keys are cached by httpd until the mtime
+ (modified time) of the mapfile changes, or the httpd server is
+ restarted. This ensures better performance on maps that are called
+ by many requests.
+
mapfile.map.dir
and mapfiile.map.pag
. This is
normal, and you need only use the base name mapfile.map
in
your RewriteMap
directive.
+
+
+
+The looked-up keys are cached by httpd until the mtime
+(modified time) of the mapfile changes, or the httpd server is
+restarted. This ensures better performance on maps that are called
+by many requests.
+
RewriteMap
directive.
MapType: prg
, MapSource: Unix filesystem path to valid regular file
Here the source is a program, not a map file. To
-create it you can use a language of your choice, but
-the result has to be an executable program (either
-object-code or a script with the magic cookie trick
-'#!/path/to/interpreter
' as the first
-line).
This program is started once, when the Apache httpd server
-is started, and then communicates with the rewriting engine
-via its stdin
and stdout
-file-handles. For each map-function lookup it will
-receive the key to lookup as a newline-terminated string
-on stdin
. It then has to give back the
-looked-up value as a newline-terminated string on
-stdout
or the four-character string
-``NULL
'' if it fails (i.e., there
-is no corresponding value for the given key).
This feature utilizes the rewrite-map
mutex,
-which is required for reliable communication with the program.
-The mutex mechanism and lock file can be configured with the
-
External rewriting programs are not started if they're defined in a
-context that does not have on
A trivial program which will implement a 1:1 map (i.e., - key == value) could be:
-#!/usr/bin/perl -$| = 1; -while (<STDIN>) { - # ...put here any transformations or lookups... - print $_; -} -
But be very careful:
stdout
. Avoid this, as it will cause a deadloop!
-``$|=1
'' is used above, to prevent this.When a MapType of prg
is used, the MapSource is a
+ filesystem path to an executable program which will providing the
+ mapping behavior. This can be a compiled binary file, or a program
+ in an interpreted language such as Perl or Python.
This program is started once, when the Apache HTTP Server is
+ started, and then communicates with the rewriting engine via
+ STDIN
and STDOUT
. That is, for each map
+ function lookup, it expects one argument via STDIN
, and
+ should return one new-line terminated response string on
+ STDOUT
. If there is no corresponding lookup value, the
+ map program should return the four-character string
+ "NULL
" to indicate this.
External rewriting programs are not started if they're defined in
+ a context that does not have on
.
This feature utilizes the rewrite-map
mutex,
+ which is required for reliable communication with the program.
+ The mutex mechanism and lock file can be configured with the
+
A simple example is shown here which will replace all dashes with + underscores in a request URI.
+ +$| = 1;
This will
+of course vary in other languages. Buffered I/O will cause httpd to wait
+for the output, and so it will hang.MapType: dbd
or fastdbd
,
-MapSource: An SQL SELECT statement that takes a single
- argument and returns a single value.
This uses fastdbd
caches database lookups internally,
-dbd
doesn't. So dbd
incurs a
-performance penalty but responds immediately if the database
-contents are updated, while fastdbd
is more
-efficient but won't re-read database contents until server
-restart.
When a MapType of dbd
or fastdbd
is
+ used, the MapSource is a SQL SELECT statement that takes a single
+ argument and returns a single value.
There are two forms of this MapType.
+ Using a MapType of dbd
causes the query to be
+ executed with each map request, while using fastdbd
+ caches the database lookups internally. So, while
+ fastdbd
is more efficient, and therefore faster, it
+ won't pick up on changes to the database until the server is
+ restarted.
If a query returns more than one row, a random row from the result set is used.
+The
mtime
of the
-mapfile changes or the server does a restart. This way you can have
-map-functions in rules which are used for every
-request. This is no problem, because the external lookup only happens
-once!
-While you cannot declare a map in
+ per-directory context (.htaccess
files or
+ <Directory> blocks) it is possible to
+ use this map in per-directory context.