From: Christophe Jaillet This document supplements the RewriteMap
types.
The syntax of the RewriteMap
directive is as
- follows:
The syntax of the
For example, you can define a
-
You would then be able to use this map in a
-
-The RewriteMap
directive may not be used in
-<Directory> sections or .htaccess
files. You must
+The .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 @@ -121,7 +122,8 @@ may be used, and give examples of each.
When a MapType of int
is used, the MapSource is one
- of the available internal RewriteMap functions. Module authors can provide
+ of the available internal ap_register_rewrite_mapfunc
API.
The functions that are provided by default are:
@@ -141,8 +143,10 @@ may be used, and give examples of each.
- To use one of these functions, create a RewriteMap
referencing
- the int function, and then use that in your RewriteRule
:
+ To use one of these functions, create a
Redirect a URI to an all-lowercase version of itself
@@ -178,7 +182,8 @@ RewriteRule "(.*)" "${lc:$1}" [R] MatchingKey SubstValue # commentWhen the RewriteMap is invoked the argument is looked for in the +
When the
Thus, when http://example.com/product/television
is
- requested, the RewriteRule
is applied, and the request
+ requested, the /prods.php?id=993
.
So, when an image is requested and the first of these rules is
- matched, RewriteMap
looks up the string
+ matched, static
in the map file, which returns one of the
specified hostnames at random, which is then used in the
- RewriteRule
target.
If you wanted to have one of the servers more likely to be chosen (for example, if one of the server has more memory than the others, @@ -298,7 +304,8 @@ static www1|www1|www2|www3|www4 RewriteMap examplemap "dbm=sdbm:/etc/apache/mapfile.dbm" -
The type can be sdbm, gdbm, ndbm or db. +
The type can be sdbm
, gdbm
, ndbm
+ or db
.
However, it is recommended that you just use the httxt2dbm utility that is
provided with Apache HTTP Server, as it will use the correct DBM library,
@@ -313,7 +320,7 @@ $ httxt2dbm -i mapfile.txt -o mapfile.map
You can then reference the resulting file in your
-RewriteMap
directive:
mapfile.map.dir
and mapfiile.map.pag
. This is
normal, and you need only use the base name mapfile.map
in
-your RewriteMap
directive.
+your A simple example is shown here which will replace all dashes with underscores in a request URI.
-Rewrite configuration
+Rewrite configuration
If a query returns more than one row, a random row from -the result set is used.
+ the result set is used. -The
The
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.