rewritemap.xml revision 365711300b7310a1efed8aa9f01492086882ba7c
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen<?xml version="1.0" encoding="UTF-8"?>
0a3142725875ea286597e083547d34d98f8c1f2drbowen<!DOCTYPE manualpage SYSTEM "/style/manualpage.dtd">
0a3142725875ea286597e083547d34d98f8c1f2drbowen<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
0a3142725875ea286597e083547d34d98f8c1f2drbowen<!-- $LastChangedRevision: 882992 $ -->
0a3142725875ea286597e083547d34d98f8c1f2drbowen<!--
0a3142725875ea286597e083547d34d98f8c1f2drbowen Licensed to the Apache Software Foundation (ASF) under one or more
0a3142725875ea286597e083547d34d98f8c1f2drbowen contributor license agreements. See the NOTICE file distributed with
0a3142725875ea286597e083547d34d98f8c1f2drbowen this work for additional information regarding copyright ownership.
0a3142725875ea286597e083547d34d98f8c1f2drbowen The ASF licenses this file to You under the Apache License, Version 2.0
0a3142725875ea286597e083547d34d98f8c1f2drbowen (the "License"); you may not use this file except in compliance with
0a3142725875ea286597e083547d34d98f8c1f2drbowen the License. You may obtain a copy of the License at
0a3142725875ea286597e083547d34d98f8c1f2drbowen
0a3142725875ea286597e083547d34d98f8c1f2drbowen http://www.apache.org/licenses/LICENSE-2.0
0a3142725875ea286597e083547d34d98f8c1f2drbowen
0a3142725875ea286597e083547d34d98f8c1f2drbowen Unless required by applicable law or agreed to in writing, software
0a3142725875ea286597e083547d34d98f8c1f2drbowen distributed under the License is distributed on an "AS IS" BASIS,
0a3142725875ea286597e083547d34d98f8c1f2drbowen WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0a3142725875ea286597e083547d34d98f8c1f2drbowen See the License for the specific language governing permissions and
0a3142725875ea286597e083547d34d98f8c1f2drbowen limitations under the License.
0a3142725875ea286597e083547d34d98f8c1f2drbowen-->
0a3142725875ea286597e083547d34d98f8c1f2drbowen<manualpage metafile="rewritemap.xml.meta">
0a3142725875ea286597e083547d34d98f8c1f2drbowen <parentdocument href="./">Rewrite</parentdocument>
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen <title>Using RewriteMap</title>
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen <summary>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <p>This document supplements the <module>mod_rewrite</module>
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen<a href="/mod/mod_rewrite.html">reference documentation</a>. It describes
0a3142725875ea286597e083547d34d98f8c1f2drbowenthe use of the <directive module="mod_rewrite">RewriteMap</directive> directive,
0a3142725875ea286597e083547d34d98f8c1f2drbowenand provides examples of each of the various <code>RewriteMap</code> types.</p>
0a3142725875ea286597e083547d34d98f8c1f2drbowen <note type="warning">Note that many of these examples won't work unchanged in your
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowenparticular server configuration, so it's important that you understand
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowenthem, rather than merely cutting and pasting the examples into your
0a3142725875ea286597e083547d34d98f8c1f2drbowenconfiguration.</note>
0a3142725875ea286597e083547d34d98f8c1f2drbowen </summary>
0a3142725875ea286597e083547d34d98f8c1f2drbowen <seealso> <a href="/mod/mod_rewrite.html">Module documentation</a> </seealso>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <seealso> <a href="intro.html">mod_rewrite introduction</a> </seealso>
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen <seealso> <a href="remapping.html">Redirection and remapping</a> </seealso>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <seealso> <a href="access.html">Controlling access</a> </seealso>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <seealso> <a href="vhosts.html">Virtual hosts</a> </seealso>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <seealso> <a href="proxy.html">Proxying</a> </seealso>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <seealso> <a href="advanced.html">Advanced techniques and tricks</a> </seealso>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <seealso> <a href="avoid.html">When not to use mod_rewrite</a> </seealso>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <section id="introduction">
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <title>Introduction</title>
365711300b7310a1efed8aa9f01492086882ba7crbowen <p>The <directive>RewriteMap</directive> directive defines a
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen <em>Rewriting Map</em> which can be used inside rule
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen substitution strings by the mapping-functions to
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen insert/substitute fields through a key lookup. The source of
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen this lookup can be of various types.</p>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <p>The <a id="mapfunc" name="mapfunc"><em>MapName</em></a> is
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen the name of the map and will be used to specify a
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen mapping-function for the substitution strings of a rewriting
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen rule via one of the following constructs:</p>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <p class="indent">
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <strong>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <code>${</code>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <em>MapName</em>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <code>:</code>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <em>LookupKey</em>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <code>}</code>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <br/>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <code>${</code>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <em>MapName</em>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <code>:</code>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <em>LookupKey</em>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <code>|</code>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <em>DefaultValue</em>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <code>}</code>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen </strong>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen </p>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <p>When such a construct occurs, the map <em>MapName</em> is
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen consulted and the key <em>LookupKey</em> is looked-up. If the
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen key is found, the map-function construct is substituted by
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <em>SubstValue</em>. If the key is not found then it is
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen substituted by <em>DefaultValue</em> or by the empty string
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen if no <em>DefaultValue</em> was specified.</p>
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen <p>For example, you might define a
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen <directive>RewriteMap</directive> as:</p>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <example>
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen RewriteMap examplemap txt:/path/to/file/map.txt
0a3142725875ea286597e083547d34d98f8c1f2drbowen </example>
0a3142725875ea286597e083547d34d98f8c1f2drbowen <p>You would then be able to use this map in a
0a3142725875ea286597e083547d34d98f8c1f2drbowen <directive>RewriteRule</directive> as follows:</p>
0a3142725875ea286597e083547d34d98f8c1f2drbowen <example>
0a3142725875ea286597e083547d34d98f8c1f2drbowen RewriteRule ^/ex/(.*) ${examplemap:$1}
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen </example>
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen <p>The following combinations for <em>MapType</em> and
0a3142725875ea286597e083547d34d98f8c1f2drbowen <em>MapSource</em> can be used:</p>
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen </section>
0a3142725875ea286597e083547d34d98f8c1f2drbowen <section id="txt">
0a3142725875ea286597e083547d34d98f8c1f2drbowen <title>txt: Plain text maps</title>
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen <p>MapType: <code>txt</code>, MapSource: Unix filesystem
0a3142725875ea286597e083547d34d98f8c1f2drbowen path to valid regular file</p>
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen <p>This is the standard rewriting map feature where the
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen <em>MapSource</em> is a plain ASCII file containing
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen either blank lines, comment lines (starting with a '#'
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen character) or pairs like the following - one per
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen line.</p>
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen <p class="indent">
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen <strong>
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen <em>MatchingKey</em>
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen <em>SubstValue</em>
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen </strong>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen </p>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <example>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <title>Example</title>
0a3142725875ea286597e083547d34d98f8c1f2drbowen <pre>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen##
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen## map.txt -- rewriting map
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen##
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowenRalf.S.Engelschall rse # Bastard Operator From Hell
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowenMr.Joe.Average joe # Mr. Average
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen</pre>
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen </example>
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen <example>
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowenRewriteMap real-to-user txt:/path/to/file/map.txt
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen</example>
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen </section>
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen <section id="rnd">
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen <title>rnd: Randomized Plain Text</title>
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen <p>MapType: <code>rnd</code>, MapSource: Unix filesystem
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen path to valid regular file</p>
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen <p>This is identical to the Standard Plain Text variant
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen above but with a special post-processing feature: After
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen looking up a value it is parsed according to contained
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen ``<code>|</code>'' characters which have the meaning of
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen ``or''. In other words they indicate a set of
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen alternatives from which the actual returned value is
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen chosen randomly. For example, you might use the following map
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen file and directives to provide a random load balancing between
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen several back-end server, via a reverse-proxy. Images are sent
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen to one of the servers in the 'static' pool, while everything
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen else is sent to one of the 'dynamic' pool.</p>
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen <p>Example:</p>
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen <example>
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen <title>Rewrite map file</title>
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen <pre>
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen##
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen## map.txt -- rewriting map
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen##
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowenstatic www1|www2|www3|www4
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowendynamic www5|www6
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen</pre>
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen </example>
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen <example><title>Configuration directives</title>
0a3142725875ea286597e083547d34d98f8c1f2drbowenRewriteMap servers rnd:/path/to/file/map.txt<br/>
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen<br/>
0a3142725875ea286597e083547d34d98f8c1f2drbowenRewriteRule ^/(.*\.(png|gif|jpg)) http://${servers:static}/$1
0a3142725875ea286597e083547d34d98f8c1f2drbowen[NC,P,L]<br/>
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowenRewriteRule ^/(.*) http://${servers:dynamic}/$1 [P,L]
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen</example>
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen </section>
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen <section id="dbm">
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen <title>dbm: DBM Hash File</title>
0a3142725875ea286597e083547d34d98f8c1f2drbowen <p>MapType:
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen <code>dbm[=<em>type</em>]</code>, MapSource: Unix filesystem
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen path to valid regular file</p>
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen <p>Here the source is a binary format DBM file containing
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen the same contents as a <em>Plain Text</em> format file, but
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen in a special representation which is optimized for really
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen fast lookups. The <em>type</em> can be sdbm, gdbm, ndbm, or
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen db depending on <a href="/install.html#dbm">compile-time
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen settings</a>. If the <em>type</em> is omitted, the
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen compile-time default will be chosen.</p>
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen <p>To create a dbm file from a source text file, use the <a href="/programs/httxt2dbm.html">httxt2dbm</a> utility.</p>
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen <example>
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen$ httxt2dbm -i mapfile.txt -o mapfile.map
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen</example>
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen </section>
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen <section id="int">
721755eb7ca9b3bf233f223d48e43edd7795c6ebrbowen <title>int: Internal Function</title>
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen <p>
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen MapType: <code>int</code>, MapSource: Internal Apache httpd
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen function</p>
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen <p>Here, the source is an internal Apache httpd function.
0a3142725875ea286597e083547d34d98f8c1f2drbowen Currently you cannot create your own, but the following
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen functions already exist:</p>
0a3142725875ea286597e083547d34d98f8c1f2drbowen <ul>
0a3142725875ea286597e083547d34d98f8c1f2drbowen <li><strong>toupper</strong>:<br/>
0a3142725875ea286597e083547d34d98f8c1f2drbowen Converts the key to all upper case.</li>
0a3142725875ea286597e083547d34d98f8c1f2drbowen <li><strong>tolower</strong>:<br/>
0a3142725875ea286597e083547d34d98f8c1f2drbowen Converts the key to all lower case.</li>
0a3142725875ea286597e083547d34d98f8c1f2drbowen <li><strong>escape</strong>:<br/>
0a3142725875ea286597e083547d34d98f8c1f2drbowen Translates special characters in the key to
0a3142725875ea286597e083547d34d98f8c1f2drbowen hex-encodings.</li>
0a3142725875ea286597e083547d34d98f8c1f2drbowen <li><strong>unescape</strong>:<br/>
0a3142725875ea286597e083547d34d98f8c1f2drbowen Translates hex-encodings in the key back to
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen special characters.</li>
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen </ul>
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen </section>
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen <section id="prg"><title>prg: External Rewriting Program</title><p>
0a3142725875ea286597e083547d34d98f8c1f2drbowen MapType: <code>prg</code>, MapSource: Unix filesystem
0a3142725875ea286597e083547d34d98f8c1f2drbowen path to valid regular file
0a3142725875ea286597e083547d34d98f8c1f2drbowen </p><p>Here the source is a program, not a map file. To
0a3142725875ea286597e083547d34d98f8c1f2drbowen create it you can use a language of your choice, but
0a3142725875ea286597e083547d34d98f8c1f2drbowen the result has to be an executable program (either
0a3142725875ea286597e083547d34d98f8c1f2drbowen object-code or a script with the magic cookie trick
0a3142725875ea286597e083547d34d98f8c1f2drbowen '<code>#!/path/to/interpreter</code>' as the first
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen line).</p><p>This program is started once, when the Apache httpd server
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen is started, and then communicates with the rewriting engine
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen via its <code>stdin</code> and <code>stdout</code>
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen file-handles. For each map-function lookup it will
0a3142725875ea286597e083547d34d98f8c1f2drbowen receive the key to lookup as a newline-terminated string
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen on <code>stdin</code>. It then has to give back the
0a3142725875ea286597e083547d34d98f8c1f2drbowen looked-up value as a newline-terminated string on
0a3142725875ea286597e083547d34d98f8c1f2drbowen <code>stdout</code> or the four-character string
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen ``<code>NULL</code>'' if it fails (<em>i.e.</em>, there
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen is no corresponding value for the given key).</p><p>This feature utilizes the <code>rewrite-map</code> mutex,
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen which is required for reliable communication with the program.
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen The mutex mechanism and lock file can be configured with the
0a3142725875ea286597e083547d34d98f8c1f2drbowen <directive module="core">Mutex</directive> directive.</p><p>External rewriting programs are not started if they're defined in a
0a3142725875ea286597e083547d34d98f8c1f2drbowen context that does not have <directive>RewriteEngine</directive> set to
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen <code>on</code></p>.
0a3142725875ea286597e083547d34d98f8c1f2drbowen
0a3142725875ea286597e083547d34d98f8c1f2drbowen <p>A trivial program which will implement a 1:1 map (<em>i.e.</em>,
0a3142725875ea286597e083547d34d98f8c1f2drbowen key == value) could be:</p><example><pre>
0a3142725875ea286597e083547d34d98f8c1f2drbowen#!/usr/bin/perl
0a3142725875ea286597e083547d34d98f8c1f2drbowen$| = 1;
0a3142725875ea286597e083547d34d98f8c1f2drbowenwhile (&lt;STDIN&gt;) {
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen # ...put here any transformations or lookups...
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen print $_;
0a3142725875ea286597e083547d34d98f8c1f2drbowen}
0a3142725875ea286597e083547d34d98f8c1f2drbowen</pre></example><p>But be very careful:</p><ol><li>``<em>Keep it simple, stupid</em>'' (KISS).
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowenIf this program hangs, it will cause Apache httpd to hang
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowenwhen trying to use the relevant rewrite rule.</li><li>A common mistake is to use buffered I/O on
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen<code>stdout</code>. Avoid this, as it will cause a deadloop!
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen``<code>$|=1</code>'' is used above, to prevent this.</li></ol></section>
0a3142725875ea286597e083547d34d98f8c1f2drbowen <section id="dbd">
0a3142725875ea286597e083547d34d98f8c1f2drbowen <title>dbd or fastdbd: SQL Query</title>
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen <p>MapType: <code>dbd</code> or <code>fastdbd</code>,
0a3142725875ea286597e083547d34d98f8c1f2drbowenMapSource: An SQL SELECT statement that takes a single
0a3142725875ea286597e083547d34d98f8c1f2drbowen argument and returns a single value.</p>
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen <p>This uses <module>mod_dbd</module> to implement a rewritemap
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowenby lookup in an SQL database. There are two forms:
0a3142725875ea286597e083547d34d98f8c1f2drbowen<code>fastdbd</code> caches database lookups internally,
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen<code>dbd</code> doesn't. So <code>dbd</code> incurs a
0a3142725875ea286597e083547d34d98f8c1f2drbowenperformance penalty but responds immediately if the database
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowencontents are updated, while <code>fastdbd</code> is more
0a3142725875ea286597e083547d34d98f8c1f2drbowenefficient but won't re-read database contents until server
0a3142725875ea286597e083547d34d98f8c1f2drbowenrestart.</p>
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen <p>If a query returns more than one row, a random row from
0a3142725875ea286597e083547d34d98f8c1f2drbowenthe result set is used.</p>
0a3142725875ea286597e083547d34d98f8c1f2drbowen <example><title>Example</title>
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowenRewriteMap myquery "fastdbd:SELECT destination FROM rewrite WHERE source = %s"
d0978b1d74a5614cfc225aa772fe90344bf85d0drbowen</example>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen </section>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <section id="summary">
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <title>Summary</title>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <p>The <directive>RewriteMap</directive> directive can occur more than
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen once. For each mapping-function use one
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <directive>RewriteMap</directive> directive to declare its rewriting
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen mapfile. While you cannot <strong>declare</strong> a map in
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen per-directory context it is of course possible to
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <strong>use</strong> this map in per-directory context. </p>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen <note><title>Note</title> For plain text and DBM format files the
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowenlooked-up keys are cached in-core until the <code>mtime</code> of the
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowenmapfile changes or the server does a restart. This way you can have
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowenmap-functions in rules which are used for <strong>every</strong>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowenrequest. This is no problem, because the external lookup only happens
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowenonce!
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen</note>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen </section>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen</manualpage>
83f3471f5de14ca3def6d7935cd1af1604874bfdrbowen