rewritemap.html.en revision 9a58dc6a2b26ec128b1270cf48810e705f1a90db
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak This file is generated from xml source: DO NOT EDIT
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak<title>Using RewriteMap - Apache HTTP Server</title>
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak<link href="/images/favicon.ico" rel="shortcut icon" /></head>
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="/faq/">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p>
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak<div class="up"><a href="./"><img title="<-" alt="<-" src="/images/left.gif" /></a></div>
4b5981e276e93df97c34e4da05ca5cf8bbd937dand<a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="../">Version 2.3</a> > <a href="./">Rewrite</a></div><div id="page-content"><div id="preamble"><h1>Using RewriteMap</h1>
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak<p><span>Available Languages: </span><a href="/en/rewrite/rewritemap.html" title="English"> en </a></p>
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak <p>This document supplements the <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code>
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem<a href="/mod/mod_rewrite.html">reference documentation</a>. It describes
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluemthe use of the <code class="directive"><a href="/mod/mod_rewrite.html#rewritemap">RewriteMap</a></code> directive,
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniakand provides examples of each of the various <code>RewriteMap</code> types.</p>
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak <div class="warning">Note that many of these examples won't work unchanged in your
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniakparticular server configuration, so it's important that you understand
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniakthem, rather than merely cutting and pasting the examples into your
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniakconfiguration.</div>
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak<div id="quickview"><ul id="toc"><li><img alt="" src="/images/down.gif" /> <a href="#introduction">Introduction</a></li>
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak<li><img alt="" src="/images/down.gif" /> <a href="#txt">txt: Plain text maps</a></li>
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak<li><img alt="" src="/images/down.gif" /> <a href="#rnd">rnd: Randomized Plain Text</a></li>
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak<li><img alt="" src="/images/down.gif" /> <a href="#dbm">dbm: DBM Hash File</a></li>
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak<li><img alt="" src="/images/down.gif" /> <a href="#int">int: Internal Function</a></li>
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak<li><img alt="" src="/images/down.gif" /> <a href="#prg">prg: External Rewriting Program</a></li>
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak<li><img alt="" src="/images/down.gif" /> <a href="#dbd">dbd or fastdbd: SQL Query</a></li>
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak<li><img alt="" src="/images/down.gif" /> <a href="#summary">Summary</a></li>
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak</ul><h3>See also</h3><ul class="seealso"><li><a href="/mod/mod_rewrite.html">Module documentation</a></li><li><a href="intro.html">mod_rewrite introduction</a></li><li><a href="remapping.html">Redirection and remapping</a></li><li><a href="access.html">Controlling access</a></li><li><a href="vhosts.html">Virtual hosts</a></li><li><a href="proxy.html">Proxying</a></li><li><a href="advanced.html">Advanced techniques</a></li><li><a href="avoid.html">When not to use mod_rewrite</a></li></ul></div>
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak<h2><a name="introduction" id="introduction">Introduction</a></h2>
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak The <code class="directive"><a href="/mod/mod_rewrite.html#rewritemap">RewriteMap</a></code> directive
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak defines an external function which can be called in the context of
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak <code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> or
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak <code class="directive"><a href="/mod/mod_rewrite.html#rewritecond">RewriteCond</a></code> directives to
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak perform rewriting that is too complicated, or too specialized to be
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak performed just by regular expressions. The source of this lookup can
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak be any of the types listed in the sections below, and enumerated in
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak the <code class="directive"><a href="/mod/mod_rewrite.html#rewritemap">RewriteMap</a></code> reference
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak documentation.</p>
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak <p>The syntax of the <code>RewriteMap</code> directive is as
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak follows:</p>
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniakRewriteMap <em>MapName</em> <em>MapType</em>:<em>MapSource</em>
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak <p>The <a id="mapfunc" name="mapfunc"><em>MapName</em></a> is an
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak arbitray name that you assign to the map, and which you will use in
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak directives later on. Arguments are passed to the map via the
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak following syntax:</p>
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak <code>${</code> <em>MapName</em> <code>:</code> <em>LookupKey</em>
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak <code>}</code> <br /> <code>${</code> <em>MapName</em> <code>:</code>
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak <em>LookupKey</em> <code>|</code> <em>DefaultValue</em> <code>}</code>
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak <p>When such a construct occurs, the map <em>MapName</em> is
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak consulted and the key <em>LookupKey</em> is looked-up. If the
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak key is found, the map-function construct is substituted by
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak <em>SubstValue</em>. If the key is not found then it is
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak substituted by <em>DefaultValue</em> or by the empty string
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak <p>For example, you might define a
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak <p>You would then be able to use this map in a
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak <code class="directive">RewriteRule</code> as follows:</p>
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak RewriteRule ^/ex/(.*) ${examplemap:$1}
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak<p>A default value can be specified in the event that nothing is found
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniakin the map:</p>
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniakRewriteRule ^/ex/(.*) ${examplemap:$1|/not_found.html}
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen<div class="note"><h3>Per-directory and .htaccess context</h3>
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniakThe <code>RewriteMap</code> directive may not be used in
9c1260efa52c82c2a58e5b5f20cd6902563d95f5rbowen<Directory> sections or <code>.htaccess</code> files. You must
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniakdeclare the map in server or virtualhost context. You may use the map,
RewriteRule ^/product/(.*) /prods.php?id=${product2id:$1|NOTFOUND} [PT]
RewriteRule ^product/(.*) /prods.php?id=${product2id:$1|NOTFOUND} [PT]
However, it is recommended that you just use the <a href="/programs/httxt2dbm.html">httxt2dbm</a> utility that is
a context that does not have <code class="directive"><a href="/mod/mod_rewrite.html#rewriteengine">RewriteEngine</a></code> set to
<p><code class="module"><a href="/mod/mod_dbd.html">mod_dbd</a></code> will need to be configured to point at
<p><span>Available Languages: </span><a href="/en/rewrite/rewritemap.html" title="English"> en </a></p>
<p class="apache">Copyright 2011 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="/faq/">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p></div>