rewritemap.xml revision dcfbe1c582e8e138f6f36ac7c4eb4d3f1e241346
97a9a944b5887e91042b019776c41d5dd74557aferikabele<!DOCTYPE manualpage SYSTEM "/style/manualpage.dtd">
97a9a944b5887e91042b019776c41d5dd74557aferikabele<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive<!-- $LastChangedRevision: 882992 $ -->
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive Licensed to the Apache Software Foundation (ASF) under one or more
fe64b2ba25510d8c9dba5560a2d537763566cf40nd contributor license agreements. See the NOTICE file distributed with
fe64b2ba25510d8c9dba5560a2d537763566cf40nd this work for additional information regarding copyright ownership.
fe64b2ba25510d8c9dba5560a2d537763566cf40nd The ASF licenses this file to You under the Apache License, Version 2.0
fe64b2ba25510d8c9dba5560a2d537763566cf40nd (the "License"); you may not use this file except in compliance with
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen the License. You may obtain a copy of the License at
fe64b2ba25510d8c9dba5560a2d537763566cf40nd Unless required by applicable law or agreed to in writing, software
fe64b2ba25510d8c9dba5560a2d537763566cf40nd distributed under the License is distributed on an "AS IS" BASIS,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen See the License for the specific language governing permissions and
3f08db06526d6901aa08c110b5bc7dde6bc39905nd limitations under the License.
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd <p>This document supplements the <module>mod_rewrite</module>
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd<a href="/mod/mod_rewrite.html">reference documentation</a>. It describes
660c7c6d7e175238807ffc144c0f8e746bf2cfb0minfrinthe use of the <directive module="mod_rewrite">RewriteMap</directive> directive,
7f5b59ccc63c0c0e3e678a168f09ee6a2f51f9d0ndand provides examples of each of the various <code>RewriteMap</code> types.</p>
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd <note type="warning">Note that many of these examples won't work unchanged in your
fe64b2ba25510d8c9dba5560a2d537763566cf40ndparticular server configuration, so it's important that you understand
fe64b2ba25510d8c9dba5560a2d537763566cf40ndthem, rather than merely cutting and pasting the examples into your
fe64b2ba25510d8c9dba5560a2d537763566cf40ndconfiguration.</note>
fe64b2ba25510d8c9dba5560a2d537763566cf40nd </summary>
fe64b2ba25510d8c9dba5560a2d537763566cf40nd <seealso><a href="/mod/mod_rewrite.html">Module documentation</a></seealso>
fe64b2ba25510d8c9dba5560a2d537763566cf40nd <seealso><a href="intro.html">mod_rewrite introduction</a></seealso>
fe64b2ba25510d8c9dba5560a2d537763566cf40nd <seealso><a href="remapping.html">Redirection and remapping</a></seealso>
97a9a944b5887e91042b019776c41d5dd74557aferikabele <seealso><a href="access.html">Controlling access</a></seealso>
f67d046f3809f2659fa2b9842ca17ff87a1f01c4nd <seealso><a href="vhosts.html">Virtual hosts</a></seealso>
f67d046f3809f2659fa2b9842ca17ff87a1f01c4nd <seealso><a href="advanced.html">Advanced techniques and tricks</a></seealso>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <seealso><a href="avoid.html">When not to use mod_rewrite</a></seealso>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive The <directive module="mod_rewrite">RewriteMap</directive> directive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive defines an external function which can be called in the context of
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <directive module="mod_rewrite">RewriteRule</directive> or
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <directive module="mod_rewrite">RewriteCond</directive> directives to
136489fb8f0fe36dbcad3064a335eb86bfbeb5c6rbowen perform rewriting that is too complicated, or too specialized to be
97a9a944b5887e91042b019776c41d5dd74557aferikabele performed just by regular expressions. The source of this lookup can
06ba4a61654b3763ad65f52283832ebf058fdf1cslive be any of the types listed in the sections below, and enumerated in
06ba4a61654b3763ad65f52283832ebf058fdf1cslive the <directive module="mod_rewrite">RewriteMap</directive> reference
97a9a944b5887e91042b019776c41d5dd74557aferikabele documentation.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>The syntax of the <code>RewriteMap</code> directive is as
06ba4a61654b3763ad65f52283832ebf058fdf1cslive follows:</p>
fe64b2ba25510d8c9dba5560a2d537763566cf40ndRewriteMap <em>MapName</em> <em>MapType</em>:<em>MapSource</em>
117c1f888a14e73cdd821dc6c23eb0411144a41cnd <p>The <a id="mapfunc" name="mapfunc"><em>MapName</em></a> is an
117c1f888a14e73cdd821dc6c23eb0411144a41cnd arbitray name that you assign to the map, and which you will use in
117c1f888a14e73cdd821dc6c23eb0411144a41cnd directives later on. Arguments are passed to the map via the
fe64b2ba25510d8c9dba5560a2d537763566cf40nd following syntax:</p>
9bcfc3697a91b5215893a7d0206865b13fc72148nd <code>${</code> <em>MapName</em> <code>:</code> <em>LookupKey</em>
9bcfc3697a91b5215893a7d0206865b13fc72148nd <code>}</code> <br/> <code>${</code> <em>MapName</em> <code>:</code>
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh <em>LookupKey</em> <code>|</code> <em>DefaultValue</em> <code>}</code>
a1ceb0cd0152edea3c72f4d9dcb352bae6ef273fjorton <p>When such a construct occurs, the map <em>MapName</em> is
a1ceb0cd0152edea3c72f4d9dcb352bae6ef273fjorton consulted and the key <em>LookupKey</em> is looked-up. If the
a1ceb0cd0152edea3c72f4d9dcb352bae6ef273fjorton key is found, the map-function construct is substituted by
a1ceb0cd0152edea3c72f4d9dcb352bae6ef273fjorton <em>SubstValue</em>. If the key is not found then it is
a1ceb0cd0152edea3c72f4d9dcb352bae6ef273fjorton substituted by <em>DefaultValue</em> or by the empty string
a1ceb0cd0152edea3c72f4d9dcb352bae6ef273fjorton <p>For example, you might define a
a1ceb0cd0152edea3c72f4d9dcb352bae6ef273fjorton <p>You would then be able to use this map in a
a1ceb0cd0152edea3c72f4d9dcb352bae6ef273fjorton RewriteRule ^/ex/(.*) ${examplemap:$1}
a1ceb0cd0152edea3c72f4d9dcb352bae6ef273fjorton<p>A default value can be specified in the event that nothing is found
a1ceb0cd0152edea3c72f4d9dcb352bae6ef273fjortonin the map:</p>
a1ceb0cd0152edea3c72f4d9dcb352bae6ef273fjortonRewriteRule ^/ex/(.*) ${examplemap:$1|/not_found.html}
fe64b2ba25510d8c9dba5560a2d537763566cf40nd<p>The sections that follow describe the various <em>MapType</em>s that
75241911a05371c31eb43e91cd40645a905408cccolmmay be used, and give examples of each.</p>
fe64b2ba25510d8c9dba5560a2d537763566cf40nd </section>
fe64b2ba25510d8c9dba5560a2d537763566cf40nd <p>When a MapType of <code>txt</code>is used, the MapSource is a filesystem path to a
fe64b2ba25510d8c9dba5560a2d537763566cf40nd plain-text mapping file, containing space-separated key/value pair
75241911a05371c31eb43e91cd40645a905408cccolm per line. Optionally, a line may be contain a comment, starting with
d8e53ebbaf8cdc872236a202b5a9fc9997348a34covener a '#' character.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>For example, the following might be valid entries in a map
f2c4476994729750806eaa70d8b55fa2b3eba25brbowen # Comment line<br />
bbe82c56451e415b93ac24e6ad928dcac01519e1humbedooh <strong><em>MatchingKey</em> <em>SubstValue</em></strong><br />
bbe82c56451e415b93ac24e6ad928dcac01519e1humbedooh <strong><em>MatchingKey</em> <em>SubstValue</em></strong> # comment<br />
e487d6c09669296f94a5190cc34586a98e624a00nd <p>When the RewriteMap is invoked the argument is looked for in the
f67d046f3809f2659fa2b9842ca17ff87a1f01c4nd first argument of a line, and, if found, the substitution value is
23255b04d466bf2621c4dd4ae1b025a9c5639e1ahumbedooh returned.</p>
f2c4476994729750806eaa70d8b55fa2b3eba25brbowen <p>For example, we might use a mapfile to translate product names to
fe64b2ba25510d8c9dba5560a2d537763566cf40nd product IDs for easier-to-remember URLs, using the following
fe64b2ba25510d8c9dba5560a2d537763566cf40nd recipe:</p>
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd RewriteMap product2id txt:/etc/apache2/productmap.txt<br />
660c7c6d7e175238807ffc144c0f8e746bf2cfb0minfrin RewriteRule ^/product/(.*) /prods.php?id=${product2id:$1|NOTFOUND} [PT]
7f5b59ccc63c0c0e3e678a168f09ee6a2f51f9d0nd </example>
727872d18412fc021f03969b8641810d8896820bhumbedooh <p>We assume here that the <code>prods.php</code> script knows what
0d0ba3a410038e179b695446bb149cce6264e0abnd to do when it received an argument of <code>id=NOTFOUND</code> when
727872d18412fc021f03969b8641810d8896820bhumbedooh a product is not found in the lookup map.</p>
0d0ba3a410038e179b695446bb149cce6264e0abnd <p>The file <code>/etc/apache2/productmap.txt</code> then contains
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh the following:</p>
ac082aefa89416cbdc9a1836eaf3bed9698201c8humbedooh## productmap.txt - Product to ID map file
0d0ba3a410038e179b695446bb149cce6264e0abndtelevision 993
0d0ba3a410038e179b695446bb149cce6264e0abndfishingrod 043
0d0ba3a410038e179b695446bb149cce6264e0abndbasketball 418
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedoohtelephone 328
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd <p>Thus, when <code>http://example.com/product/television</code> is
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd requested, the <code>RewriteRule</code> is applied, and the request
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd is internally mapped to <code>/prods.php?id=993</code>.</p>
RewriteRule ^product/(.*) /prods.php?id=${product2id:$1|NOTFOUND} [PT]
## map.txt -- rewriting map
<p>To create a dbm file from a source text file, use the <a href="/programs/httxt2dbm.html">httxt2dbm</a> utility.</p>
is no corresponding value for the given key).</p><p>This feature utilizes the <code>rewrite-map</code> mutex,
<directive module="core">Mutex</directive> directive.</p><p>External rewriting programs are not started if they're defined in a
# ...put here any transformations or lookups...