mod_rewrite.xml revision 36088d24dae5b2cc8124264fc6a9ba349ba81adc
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<?xml version="1.0"?>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<!DOCTYPE modulesynopsis SYSTEM "/style/modulesynopsis.dtd">
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<!-- $LastChangedRevision$ -->
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<!--
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess Copyright 2002-2005 The Apache Software Foundation or its licensors, as
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess applicable.
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess Licensed under the Apache License, Version 2.0 (the "License");
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess you may not use this file except in compliance with the License.
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess You may obtain a copy of the License at
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess http://www.apache.org/licenses/LICENSE-2.0
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess Unless required by applicable law or agreed to in writing, software
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess distributed under the License is distributed on an "AS IS" BASIS,
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess See the License for the specific language governing permissions and
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess limitations under the License.
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess-->
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<modulesynopsis metafile="mod_rewrite.xml.meta">
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<name>mod_rewrite</name>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<description>Provides a rule-based rewriting engine to rewrite requested
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessURLs on the fly</description>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<status>Extension</status>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<sourcefile>mod_rewrite.c</sourcefile>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<identifier>rewrite_module</identifier>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<compatibility>Available in Apache 1.3 and later</compatibility>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<summary>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>This module uses a rule-based rewriting engine (based on a
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess regular-expression parser) to rewrite requested URLs on the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess fly. It supports an unlimited number of rules and an
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess unlimited number of attached rule conditions for each rule to
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess provide a really flexible and powerful URL manipulation
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess mechanism. The URL manipulations can depend on various tests,
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess for instance server variables, environment variables, HTTP
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess headers, time stamps and even external database lookups in
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess various formats can be used to achieve a really granular URL
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess matching.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>This module operates on the full URLs (including the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess path-info part) both in per-server context
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess (<code>httpd.conf</code>) and per-directory context
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess (<code>.htaccess</code>) and can even generate query-string
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess parts on result. The rewritten result can lead to internal
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess sub-processing, external request redirection or even to an
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess internal proxy throughput.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>Further details, discussion, and examples, are provided in the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <a href="/rewrite/">detailed mod_rewrite documentation</a>.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</summary>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<section id="quoting"><title>Quoting Special Characters</title>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>As of Apache 1.3.20, special characters in
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <em>TestString</em> and <em>Substitution</em> strings can be
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess escaped (that is, treated as normal characters without their
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess usual special meaning) by prefixing them with a slash ('\')
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess character. In other words, you can include an actual
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess dollar-sign character in a <em>Substitution</em> string by
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess using '<code>\$</code>'; this keeps mod_rewrite from trying
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess to treat it as a backreference.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</section>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<section id="EnvVar"><title>Environment Variables</title>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>This module keeps track of two additional (non-standard)
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess CGI/SSI environment variables named <code>SCRIPT_URL</code>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess and <code>SCRIPT_URI</code>. These contain the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <em>logical</em> Web-view to the current resource, while the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess standard CGI/SSI variables <code>SCRIPT_NAME</code> and
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>SCRIPT_FILENAME</code> contain the <em>physical</em>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess System-view. </p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>Notice: These variables hold the URI/URL <em>as they were
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess initially requested</em>, <em>i.e.</em>, <em>before</em> any
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess rewriting. This is important because the rewriting process is
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess primarily used to rewrite logical URLs to physical
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess pathnames.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<example><title>Example</title>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<pre>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessSCRIPT_NAME=/sw/lib/w3s/tree/global/u/rse/.www/index.html
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessSCRIPT_FILENAME=/u/rse/.www/index.html
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessSCRIPT_URL=/u/rse/
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessSCRIPT_URI=http://en1.engelschall.com/u/rse/
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</pre>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</example>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</section>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<section id="Solutions"><title>Practical Solutions</title>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>For numerous examples of common, and not-so-common, uses for
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess mod_rewrite, see the <a href="/rewrite/rewrite_guide.html">Rewrite
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess Guide</a>, and the <a
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess href="/rewrite/rewrite_guide_advanced.html">Advanced Rewrite
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess Guide</a> documents.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</section>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<directivesynopsis>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<name>RewriteEngine</name>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<description>Enables or disables runtime rewriting engine</description>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<syntax>RewriteEngine on|off</syntax>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<default>RewriteEngine off</default>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<contextlist><context>server config</context><context>virtual host</context>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<context>directory</context><context>.htaccess</context></contextlist>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<override>FileInfo</override>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<usage>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>The <directive>RewriteEngine</directive> directive enables or
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess disables the runtime rewriting engine. If it is set to
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>off</code> this module does no runtime processing at
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess all. It does not even update the <code>SCRIPT_URx</code>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess environment variables.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>Use this directive to disable the module instead of
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess commenting out all the <directive
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess module="mod_rewrite">RewriteRule</directive> directives!</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>Note that, by default, rewrite configurations are not
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess inherited. This means that you need to have a
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>RewriteEngine on</code> directive for each virtual host
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess in which you wish to use it.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</usage>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</directivesynopsis>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<directivesynopsis>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<name>RewriteOptions</name>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<description>Sets some special options for the rewrite engine</description>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<syntax>RewriteOptions <var>Options</var></syntax>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<contextlist><context>server config</context><context>virtual host</context>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<context>directory</context><context>.htaccess</context></contextlist>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<override>FileInfo</override>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<compatibility><code>MaxRedirects</code> is no longer available in version 2.1 and
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kesslater</compatibility>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<usage>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>The <directive>RewriteOptions</directive> directive sets some
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess special options for the current per-server or per-directory
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess configuration. The <em>Option</em> string can be currently only one:</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <dl>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <dt><code>inherit</code></dt>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <dd>This forces the current configuration to inherit the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess configuration of the parent. In per-virtual-server context
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess this means that the maps, conditions and rules of the main
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess server are inherited. In per-directory context this means
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess that conditions and rules of the parent directory's
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>.htaccess</code> configuration are inherited.</dd>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess </dl>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</usage>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</directivesynopsis>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<directivesynopsis>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<name>RewriteLog</name>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<description>Sets the name of the file used for logging rewrite engine
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessprocessing</description>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<syntax>RewriteLog <em>file-path</em></syntax>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<contextlist><context>server config</context><context>virtual host</context>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</contextlist>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<usage>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>The <directive>RewriteLog</directive> directive sets the name
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess of the file to which the server logs any rewriting actions it
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess performs. If the name does not begin with a slash
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess ('<code>/</code>') then it is assumed to be relative to the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <em>Server Root</em>. The directive should occur only once per
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess server config.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<note> To disable the logging of
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess rewriting actions it is not recommended to set
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <em>Filename</em> to <code>/dev/null</code>, because
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess although the rewriting engine does not then output to a
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess logfile it still creates the logfile output internally.
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <strong>This will slow down the server with no advantage
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess to the administrator!</strong> To disable logging either
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess remove or comment out the <directive>RewriteLog</directive>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess directive or use <code>RewriteLogLevel 0</code>!
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</note>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<note type="securitywarning"><title>Security</title>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessSee the <a href="/misc/security_tips.html">Apache Security Tips</a>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessdocument for details on why your security could be compromised if the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessdirectory where logfiles are stored is writable by anyone other than
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessthe user that starts the server.
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</note>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<example><title>Example</title>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessRewriteLog "/usr/local/var/apache/logs/rewrite.log"
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</example>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</usage>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</directivesynopsis>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<directivesynopsis>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<name>RewriteLogLevel</name>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<description>Sets the verbosity of the log file used by the rewrite
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessengine</description>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<syntax>RewriteLogLevel <em>Level</em></syntax>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<default>RewriteLogLevel 0</default>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<contextlist><context>server config</context><context>virtual host</context>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</contextlist>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<usage>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>The <directive>RewriteLogLevel</directive> directive sets the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess verbosity level of the rewriting logfile. The default level 0
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess means no logging, while 9 or more means that practically all
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess actions are logged.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>To disable the logging of rewriting actions simply set
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <em>Level</em> to 0. This disables all rewrite action
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess logs.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<note> Using a high value for
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <em>Level</em> will slow down your Apache server
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess dramatically! Use the rewriting logfile at a
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <em>Level</em> greater than 2 only for debugging!
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</note>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<example><title>Example</title>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessRewriteLogLevel 3
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</example>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</usage>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</directivesynopsis>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<directivesynopsis>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<name>RewriteLock</name>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<description>Sets the name of the lock file used for <directive
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessmodule="mod_rewrite">RewriteMap</directive>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kesssynchronization</description>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<syntax>RewriteLock <em>file-path</em></syntax>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<contextlist><context>server config</context></contextlist>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<usage>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>This directive sets the filename for a synchronization
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess lockfile which mod_rewrite needs to communicate with <directive
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess module="mod_rewrite">RewriteMap</directive>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <em>programs</em>. Set this lockfile to a local path (not on a
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess NFS-mounted device) when you want to use a rewriting
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess map-program. It is not required for other types of rewriting
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess maps.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</usage>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</directivesynopsis>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<directivesynopsis>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<name>RewriteMap</name>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<description>Defines a mapping function for key-lookup</description>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<syntax>RewriteMap <em>MapName</em> <em>MapType</em>:<em>MapSource</em>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</syntax>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<contextlist><context>server config</context><context>virtual host</context>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</contextlist>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<compatibility>The choice of different dbm types is available in
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessApache 2.0.41 and later</compatibility>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<usage>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>The <directive>RewriteMap</directive> directive defines a
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <em>Rewriting Map</em> which can be used inside rule
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess substitution strings by the mapping-functions to
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess insert/substitute fields through a key lookup. The source of
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess this lookup can be of various types.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>The <a id="mapfunc" name="mapfunc"><em>MapName</em></a> is
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess the name of the map and will be used to specify a
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess mapping-function for the substitution strings of a rewriting
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess rule via one of the following constructs:</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p class="indent">
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <strong><code>${</code> <em>MapName</em> <code>:</code>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <em>LookupKey</em> <code>}</code><br />
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>${</code> <em>MapName</em> <code>:</code>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <em>LookupKey</em> <code>|</code> <em>DefaultValue</em>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>}</code></strong>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess </p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>When such a construct occurs the map <em>MapName</em> is
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess consulted and the key <em>LookupKey</em> is looked-up. If the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess key is found, the map-function construct is substituted by
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <em>SubstValue</em>. If the key is not found then it is
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess substituted by <em>DefaultValue</em> or by the empty string
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess if no <em>DefaultValue</em> was specified.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>For example, you might define a
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <directive>RewriteMap</directive> as:</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <example>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess RewriteMap examplemap txt:/path/to/file/map.txt
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess </example>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>You would then be able to use this map in a
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <directive>RewriteRule</directive> as follows:</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <example>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess RewriteRule ^/ex/(.*) ${examplemap:$1}
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess </example>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>The following combinations for <em>MapType</em> and
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <em>MapSource</em> can be used:</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <ul>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <strong>Standard Plain Text</strong><br />
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess MapType: <code>txt</code>, MapSource: Unix filesystem
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess path to valid regular file
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>This is the standard rewriting map feature where the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <em>MapSource</em> is a plain ASCII file containing
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess either blank lines, comment lines (starting with a '#'
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess character) or pairs like the following - one per
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess line.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p class="indent">
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <strong><em>MatchingKey</em>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <em>SubstValue</em></strong>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess </p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<example><title>Example</title>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<pre>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess##
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess## map.txt -- rewriting map
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess##
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessRalf.S.Engelschall rse # Bastard Operator From Hell
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessMr.Joe.Average joe # Mr. Average
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</pre>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</example>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<example>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessRewriteMap real-to-user txt:/path/to/file/map.txt
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</example>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess </li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <strong>Randomized Plain Text</strong><br />
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess MapType: <code>rnd</code>, MapSource: Unix filesystem
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess path to valid regular file
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>This is identical to the Standard Plain Text variant
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess above but with a special post-processing feature: After
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess looking up a value it is parsed according to contained
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess ``<code>|</code>'' characters which have the meaning of
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess ``or''. In other words they indicate a set of
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess alternatives from which the actual returned value is
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess chosen randomly. For example, you might use the following map
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess file and directives to provide a random load balancing between
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess several back-end server, via a reverse-proxy. Images are sent
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess to one of the servers in the 'static' pool, while everything
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess else is sent to one of the 'dynamic' pool.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>Example:</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<example><title>Rewrite map file</title>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<pre>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess##
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess## map.txt -- rewriting map
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess##
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessstatic www1|www2|www3|www4
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessdynamic www5|www6
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</pre>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</example>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<example><title>Configuration directives</title>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessRewriteMap servers rnd:/path/to/file/map.txt<br />
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<br />
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessRewriteRule ^/(.*\.(png|gif|jpg)) http://${servers:static}/$1
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess[NC,P,L]<br />
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessRewriteRule ^/(.*) http://${servers:dynamic}/$1 [P,L]
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</example>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess </li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <strong>Hash File</strong><br /> MapType:
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>dbm[=<em>type</em>]</code>, MapSource: Unix filesystem
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess path to valid regular file
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>Here the source is a binary format DBM file containing
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess the same contents as a <em>Plain Text</em> format file, but
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess in a special representation which is optimized for really
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess fast lookups. The <em>type</em> can be sdbm, gdbm, ndbm, or
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess db depending on <a href="/install.html#dbm">compile-time
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess settings</a>. If the <em>type</em> is omitted, the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess compile-time default will be chosen. You can create such a
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess file with any DBM tool or with the following Perl
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess script. Be sure to adjust it to create the appropriate
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess type of DBM. The example creates an NDBM file.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<example>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<pre>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess#!/path/to/bin/perl
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess##
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess## txt2dbm -- convert txt map to dbm format
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess##
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessuse NDBM_File;
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessuse Fcntl;
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess($txtmap, $dbmmap) = @ARGV;
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessopen(TXT, "&lt;$txtmap") or die "Couldn't open $txtmap!\n";
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kesstie (%DB, 'NDBM_File', $dbmmap,O_RDWR|O_TRUNC|O_CREAT, 0644)
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess or die "Couldn't create $dbmmap!\n";
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kesswhile (&lt;TXT&gt;) {
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess next if (/^\s*#/ or /^\s*$/);
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess $DB{$1} = $2 if (/^\s*(\S+)\s+(\S+)/);
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess}
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessuntie %DB;
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessclose(TXT);
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</pre>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</example>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<example>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess$ txt2dbm map.txt map.db
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</example>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess </li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <strong>Internal Function</strong><br />
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess MapType: <code>int</code>, MapSource: Internal Apache
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess function
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>Here the source is an internal Apache function.
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess Currently you cannot create your own, but the following
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess functions already exists:</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <ul>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <li><strong>toupper</strong>:<br />
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess Converts the looked up key to all upper case.</li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <li><strong>tolower</strong>:<br />
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess Converts the looked up key to all lower case.</li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <li><strong>escape</strong>:<br />
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess Translates special characters in the looked up key to
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess hex-encodings.</li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <li><strong>unescape</strong>:<br />
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess Translates hex-encodings in the looked up key back to
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess special characters.</li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess </ul>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess </li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <strong>External Rewriting Program</strong><br />
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess MapType: <code>prg</code>, MapSource: Unix filesystem
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess path to valid regular file
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>Here the source is a program, not a map file. To
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess create it you can use the language of your choice, but
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess the result has to be a executable (<em>i.e.</em>, either
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess object-code or a script with the magic cookie trick
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess '<code>#!/path/to/interpreter</code>' as the first
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess line).</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>This program is started once at startup of the Apache
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess servers and then communicates with the rewriting engine
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess over its <code>stdin</code> and <code>stdout</code>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess file-handles. For each map-function lookup it will
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess receive the key to lookup as a newline-terminated string
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess on <code>stdin</code>. It then has to give back the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess looked-up value as a newline-terminated string on
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>stdout</code> or the four-character string
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess ``<code>NULL</code>'' if it fails (<em>i.e.</em>, there
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess is no corresponding value for the given key). A trivial
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess program which will implement a 1:1 map (<em>i.e.</em>,
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess key == value) could be:</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<example>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<pre>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess#!/usr/bin/perl
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess$| = 1;
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kesswhile (&lt;STDIN&gt;) {
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess # ...put here any transformations or lookups...
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess print $_;
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess}
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</pre>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</example>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>But be very careful:</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <ol>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <li>``<em>Keep it simple, stupid</em>'' (KISS), because
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess if this program hangs it will hang the Apache server
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess when the rule occurs.</li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <li>Avoid one common mistake: never do buffered I/O on
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>stdout</code>! This will cause a deadloop! Hence
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess the ``<code>$|=1</code>'' in the above example...</li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <li>Use the <directive
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess module="mod_rewrite">RewriteLock</directive> directive to
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess define a lockfile mod_rewrite can use to synchronize the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess communication to the program. By default no such
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess synchronization takes place.</li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess </ol>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess </li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess </ul>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>The <directive>RewriteMap</directive> directive can occur more than
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess once. For each mapping-function use one
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <directive>RewriteMap</directive> directive to declare its rewriting
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess mapfile. While you cannot <strong>declare</strong> a map in
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess per-directory context it is of course possible to
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <strong>use</strong> this map in per-directory context. </p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<note><title>Note</title> For plain text and DBM format files the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kesslooked-up keys are cached in-core until the <code>mtime</code> of the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessmapfile changes or the server does a restart. This way you can have
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessmap-functions in rules which are used for <strong>every</strong>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessrequest. This is no problem, because the external lookup only happens
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessonce!
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</note>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</usage>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</directivesynopsis>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<directivesynopsis>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<name>RewriteBase</name>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<description>Sets the base URL for per-directory rewrites</description>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<syntax>RewriteBase <em>URL-path</em></syntax>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<default>See usage for information.</default>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<contextlist><context>directory</context><context>.htaccess</context>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</contextlist>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<override>FileInfo</override>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<usage>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>The <directive>RewriteBase</directive> directive explicitly
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess sets the base URL for per-directory rewrites. As you will see
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess below, <directive module="mod_rewrite">RewriteRule</directive>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess can be used in per-directory config files
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess (<code>.htaccess</code>). There it will act locally,
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <em>i.e.</em>, the local directory prefix is stripped at this
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess stage of processing and your rewriting rules act only on the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess remainder. At the end it is automatically added back to the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess path. The default setting is; <directive>RewriteBase</directive> <em>physical-directory-path</em></p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>When a substitution occurs for a new URL, this module has
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess to re-inject the URL into the server processing. To be able
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess to do this it needs to know what the corresponding URL-prefix
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess or URL-base is. By default this prefix is the corresponding
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess filepath itself. <strong>But at most websites URLs are NOT
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess directly related to physical filename paths, so this
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess assumption will usually be wrong!</strong> There you have to
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess use the <code>RewriteBase</code> directive to specify the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess correct URL-prefix.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<note> If your webserver's URLs are <strong>not</strong> directly
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessrelated to physical file paths, you have to use
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<directive>RewriteBase</directive> in every <code>.htaccess</code>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessfiles where you want to use <directive
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessmodule="mod_rewrite">RewriteRule</directive> directives.
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</note>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p> For example, assume the following per-directory config file:</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<example>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<pre>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess#
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess# /abc/def/.htaccess -- per-dir config file for directory /abc/def
# Remember: /abc/def is the physical path of /xyz, <em>i.e.</em>, the server
# has a 'Alias /xyz /abc/def' directive <em>e.g.</em>
#
RewriteEngine On
# let the server know that we were reached via /xyz and not
# via the physical path prefix /abc/def
RewriteBase /xyz
# now the rewriting rules
RewriteRule ^oldstuff\.html$ newstuff.html
</pre>
</example>
<p>In the above example, a request to
<code>/xyz/oldstuff.html</code> gets correctly rewritten to
the physical file <code>/abc/def/newstuff.html</code>.</p>
<note><title>For Apache Hackers</title>
<p>The following list gives detailed information about
the internal processing steps:</p>
<pre>
Request:
/xyz/oldstuff.html
Internal Processing:
/xyz/oldstuff.html -&gt; /abc/def/oldstuff.html (per-server Alias)
/abc/def/oldstuff.html -&gt; /abc/def/newstuff.html (per-dir RewriteRule)
/abc/def/newstuff.html -&gt; /xyz/newstuff.html (per-dir RewriteBase)
/xyz/newstuff.html -&gt; /abc/def/newstuff.html (per-server Alias)
Result:
/abc/def/newstuff.html
</pre>
<p>This seems very complicated but is
the correct Apache internal processing, because the
per-directory rewriting comes too late in the
process. So, when it occurs the (rewritten) request
has to be re-injected into the Apache kernel! BUT:
While this seems like a serious overhead, it really
isn't, because this re-injection happens fully
internally to the Apache server and the same
procedure is used by many other operations inside
Apache. So, you can be sure the design and
implementation is correct.</p>
</note>
</usage>
</directivesynopsis>
<directivesynopsis>
<name>RewriteCond</name>
<description>Defines a condition under which rewriting will take place
</description>
<syntax> RewriteCond
<em>TestString</em> <em>CondPattern</em></syntax>
<contextlist><context>server config</context><context>virtual host</context>
<context>directory</context><context>.htaccess</context></contextlist>
<override>FileInfo</override>
<usage>
<p>The <directive>RewriteCond</directive> directive defines a
rule condition. Precede a <directive
module="mod_rewrite">RewriteRule</directive> directive with one
or more <directive>RewriteCond</directive> directives. The following
rewriting rule is only used if its pattern matches the current
state of the URI <strong>and</strong> if these additional
conditions apply too.</p>
<p><em>TestString</em> is a string which can contains the
following expanded constructs in addition to plain text:</p>
<ul>
<li>
<strong>RewriteRule backreferences</strong>: These are
backreferences of the form
<p class="indent">
<strong><code>$N</code></strong>
</p>
(0 &lt;= N &lt;= 9) which provide access to the grouped
parts (parenthesis!) of the pattern from the
corresponding <code>RewriteRule</code> directive (the one
following the current bunch of <code>RewriteCond</code>
directives).
</li>
<li>
<strong>RewriteCond backreferences</strong>: These are
backreferences of the form
<p class="indent">
<strong><code>%N</code></strong>
</p>
(1 &lt;= N &lt;= 9) which provide access to the grouped
parts (parentheses!) of the pattern from the last matched
<code>RewriteCond</code> directive in the current bunch
of conditions.
</li>
<li>
<strong>RewriteMap expansions</strong>: These are
expansions of the form
<p class="indent">
<strong><code>${mapname:key|default}</code></strong>
</p>
See <a href="#mapfunc">the documentation for
RewriteMap</a> for more details.
</li>
<li>
<strong>Server-Variables</strong>: These are variables of
the form
<p class="indent">
<strong><code>%{</code> <em>NAME_OF_VARIABLE</em>
<code>}</code></strong>
</p>
where <em>NAME_OF_VARIABLE</em> can be a string taken
from the following list:
<table>
<columnspec><column width=".3"/><column width=".3"/>
<column width=".3"/></columnspec>
<tr>
<th>HTTP headers:</th> <th>connection &amp; request:</th> <th></th>
</tr>
<tr>
<td>
HTTP_USER_AGENT<br />
HTTP_REFERER<br />
HTTP_COOKIE<br />
HTTP_FORWARDED<br />
HTTP_HOST<br />
HTTP_PROXY_CONNECTION<br />
HTTP_ACCEPT<br />
</td>
<td>
REMOTE_ADDR<br />
REMOTE_HOST<br />
REMOTE_PORT<br />
REMOTE_USER<br />
REMOTE_IDENT<br />
REQUEST_METHOD<br />
SCRIPT_FILENAME<br />
PATH_INFO<br />
QUERY_STRING<br />
AUTH_TYPE<br />
</td>
<td></td>
</tr>
<tr>
<th>server internals:</th> <th>date and time:</th> <th>specials:</th>
</tr>
<tr>
<td>
DOCUMENT_ROOT<br />
SERVER_ADMIN<br />
SERVER_NAME<br />
SERVER_ADDR<br />
SERVER_PORT<br />
SERVER_PROTOCOL<br />
SERVER_SOFTWARE<br />
</td>
<td>
TIME_YEAR<br />
TIME_MON<br />
TIME_DAY<br />
TIME_HOUR<br />
TIME_MIN<br />
TIME_SEC<br />
TIME_WDAY<br />
TIME<br />
</td>
<td>
API_VERSION<br />
THE_REQUEST<br />
REQUEST_URI<br />
REQUEST_FILENAME<br />
IS_SUBREQ<br />
HTTPS<br />
</td>
</tr>
</table>
<note>
<p>These variables all
correspond to the similarly named HTTP
MIME-headers, C variables of the Apache server or
<code>struct tm</code> fields of the Unix system.
Most are documented elsewhere in the Manual or in
the CGI specification. Those that are special to
mod_rewrite include:</p>
<dl>
<dt><code>IS_SUBREQ</code></dt>
<dd>Will contain the text "true" if the request
currently being processed is a sub-request,
"false" otherwise. Sub-requests may be generated
by modules that need to resolve additional files
or URIs in order to complete their tasks.</dd>
<dt><code>API_VERSION</code></dt>
<dd>This is the version of the Apache module API
(the internal interface between server and
module) in the current httpd build, as defined in
include/ap_mmn.h. The module API version
corresponds to the version of Apache in use (in
the release version of Apache 1.3.14, for
instance, it is 19990320:10), but is mainly of
interest to module authors.</dd>
<dt><code>THE_REQUEST</code></dt>
<dd>The full HTTP request line sent by the
browser to the server (e.g., "<code>GET
/index.html HTTP/1.1</code>"). This does not
include any additional headers sent by the
browser.</dd>
<dt><code>REQUEST_URI</code></dt>
<dd>The resource requested in the HTTP request
line. (In the example above, this would be
"/index.html".)</dd>
<dt><code>REQUEST_FILENAME</code></dt>
<dd>The full local filesystem path to the file or
script matching the request.</dd>
<dt><code>HTTPS</code></dt>
<dd>Will contain the text "on" if the connection is
using SSL/TLS, or "off" otherwise. (This variable
can be safely used regardless of whether
<module>mod_ssl</module> is loaded).</dd>
</dl>
</note>
</li>
</ul>
<p>Special Notes:</p>
<ol>
<li>The variables SCRIPT_FILENAME and REQUEST_FILENAME
contain the same value, <em>i.e.</em>, the value of the
<code>filename</code> field of the internal
<code>request_rec</code> structure of the Apache server.
The first name is just the commonly known CGI variable name
while the second is the consistent counterpart to
REQUEST_URI (which contains the value of the
<code>uri</code> field of <code>request_rec</code>).</li>
<li>There is the special format:
<code>%{ENV:variable}</code> where <em>variable</em> can be
any environment variable. This is looked-up via internal
Apache structures and (if not found there) via
<code>getenv()</code> from the Apache server process.</li>
<li>There is the special format:
<code>%{SSL:variable}</code> where <em>variable</em> is the
name of an <a href="mod_ssl.html#envvars">SSL environment
variable</a>; this can be used whether or not
<module>mod_ssl</module> is loaded, but will always expand to
the empty string if it is not. Example:
<code>%{SSL:SSL_CIPHER_USEKEYSIZE}</code> may expand to
<code>128</code>.</li>
<li>There is the special format:
<code>%{HTTP:header}</code> where <em>header</em> can be
any HTTP MIME-header name. This is looked-up from the HTTP
request. Example: <code>%{HTTP:Proxy-Connection}</code> is
the value of the HTTP header
``<code>Proxy-Connection:</code>''.</li>
<li>There is the special format
<code>%{LA-U:variable}</code> for look-aheads which perform
an internal (URL-based) sub-request to determine the final
value of <em>variable</em>. Use this when you want to use a
variable for rewriting which is actually set later in an
API phase and thus is not available at the current stage.
For instance when you want to rewrite according to the
<code>REMOTE_USER</code> variable from within the
per-server context (<code>httpd.conf</code> file) you have
to use <code>%{LA-U:REMOTE_USER}</code> because this
variable is set by the authorization phases which come
<em>after</em> the URL translation phase where mod_rewrite
operates. On the other hand, because mod_rewrite implements
its per-directory context (<code>.htaccess</code> file) via
the Fixup phase of the API and because the authorization
phases come <em>before</em> this phase, you just can use
<code>%{REMOTE_USER}</code> there.</li>
<li>There is the special format:
<code>%{LA-F:variable}</code> which performs an internal
(filename-based) sub-request to determine the final value
of <em>variable</em>. Most of the time this is the same as
LA-U above.</li>
</ol>
<p><em>CondPattern</em> is the condition pattern,
<em>i.e.</em>, a regular expression which is applied to the
current instance of the <em>TestString</em>, <em>i.e.</em>,
<em>TestString</em> is evaluated and then matched against
<em>CondPattern</em>.</p>
<p><strong>Remember:</strong> <em>CondPattern</em> is a
<em>perl compatible regular expression</em> with some
additions:</p>
<ol>
<li>You can prefix the pattern string with a
'<code>!</code>' character (exclamation mark) to specify a
<strong>non</strong>-matching pattern.</li>
<li>
There are some special variants of <em>CondPatterns</em>.
Instead of real regular expression strings you can also
use one of the following:
<ul>
<li>'<strong>&lt;CondPattern</strong>' (is lexically
lower)<br />
Treats the <em>CondPattern</em> as a plain string and
compares it lexically to <em>TestString</em>. True if
<em>TestString</em> is lexically lower than
<em>CondPattern</em>.</li>
<li>'<strong>&gt;CondPattern</strong>' (is lexically
greater)<br />
Treats the <em>CondPattern</em> as a plain string and
compares it lexically to <em>TestString</em>. True if
<em>TestString</em> is lexically greater than
<em>CondPattern</em>.</li>
<li>'<strong>=CondPattern</strong>' (is lexically
equal)<br />
Treats the <em>CondPattern</em> as a plain string and
compares it lexically to <em>TestString</em>. True if
<em>TestString</em> is lexically equal to
<em>CondPattern</em>, i.e the two strings are exactly
equal (character by character). If <em>CondPattern</em>
is just <code>""</code> (two quotation marks) this
compares <em>TestString</em> to the empty string.</li>
<li>'<strong>-d</strong>' (is
<strong>d</strong>irectory)<br />
Treats the <em>TestString</em> as a pathname and tests
if it exists and is a directory.</li>
<li>'<strong>-f</strong>' (is regular
<strong>f</strong>ile)<br />
Treats the <em>TestString</em> as a pathname and tests
if it exists and is a regular file.</li>
<li>'<strong>-s</strong>' (is regular file with
<strong>s</strong>ize)<br />
Treats the <em>TestString</em> as a pathname and tests
if it exists and is a regular file with size greater
than zero.</li>
<li>'<strong>-l</strong>' (is symbolic
<strong>l</strong>ink)<br />
Treats the <em>TestString</em> as a pathname and tests
if it exists and is a symbolic link.</li>
<li>'<strong>-x</strong>' (has e<strong>x</strong>ecutable
permissions)<br />
Treats the <em>TestString</em> as a pathname and tests
if it exists and has execution permissions. These permissions
are determined depending on the underlying OS.</li>
<li>'<strong>-F</strong>' (is existing file via
subrequest)<br />
Checks if <em>TestString</em> is a valid file and
accessible via all the server's currently-configured
access controls for that path. This uses an internal
subrequest to determine the check, so use it with care
because it decreases your servers performance!</li>
<li>'<strong>-U</strong>' (is existing URL via
subrequest)<br />
Checks if <em>TestString</em> is a valid URL and
accessible via all the server's currently-configured
access controls for that path. This uses an internal
subrequest to determine the check, so use it with care
because it decreases your server's performance!</li>
</ul>
<note><title>Notice</title>
All of these tests can
also be prefixed by an exclamation mark ('!') to
negate their meaning.
</note>
</li>
</ol>
<p>Additionally you can set special flags for
<em>CondPattern</em> by appending</p>
<p class="indent">
<strong><code>[</code><em>flags</em><code>]</code></strong>
</p>
<p>as the third argument to the <code>RewriteCond</code>
directive. <em>Flags</em> is a comma-separated list of the
following flags:</p>
<ul>
<li>'<strong><code>nocase|NC</code></strong>'
(<strong>n</strong>o <strong>c</strong>ase)<br />
This makes the test case-insensitive, <em>i.e.</em>, there
is no difference between 'A-Z' and 'a-z' both in the
expanded <em>TestString</em> and the <em>CondPattern</em>.
This flag is effective only for comparisons between
<em>TestString</em> and <em>CondPattern</em>. It has no
effect on filesystem and subrequest checks.</li>
<li>
'<strong><code>ornext|OR</code></strong>'
(<strong>or</strong> next condition)<br />
Use this to combine rule conditions with a local OR
instead of the implicit AND. Typical example:
<example>
<pre>
RewriteCond %{REMOTE_HOST} ^host1.* [OR]
RewriteCond %{REMOTE_HOST} ^host2.* [OR]
RewriteCond %{REMOTE_HOST} ^host3.*
RewriteRule ...some special stuff for any of these hosts...
</pre>
</example>
Without this flag you would have to write the cond/rule
three times.
</li>
</ul>
<p><strong>Example:</strong></p>
<p>To rewrite the Homepage of a site according to the
``<code>User-Agent:</code>'' header of the request, you can
use the following: </p>
<example>
<pre>
RewriteCond %{HTTP_USER_AGENT} ^Mozilla.*
RewriteRule ^/$ /homepage.max.html [L]
RewriteCond %{HTTP_USER_AGENT} ^Lynx.*
RewriteRule ^/$ /homepage.min.html [L]
RewriteRule ^/$ /homepage.std.html [L]
</pre>
</example>
<p>Interpretation: If you use Netscape Navigator as your
browser (which identifies itself as 'Mozilla'), then you
get the max homepage, which includes Frames, <em>etc.</em>
If you use the Lynx browser (which is Terminal-based), then
you get the min homepage, which contains no images, no
tables, <em>etc.</em> If you use any other browser you get
the standard homepage.</p>
</usage>
</directivesynopsis>
<directivesynopsis>
<name>RewriteRule</name>
<description>Defines rules for the rewriting engine</description>
<syntax>RewriteRule
<em>Pattern</em> <em>Substitution</em></syntax>
<contextlist><context>server config</context><context>virtual host</context>
<context>directory</context><context>.htaccess</context></contextlist>
<override>FileInfo</override>
<compatibility>The cookie-flag is available in Apache 2.0.40 and later.</compatibility>
<usage>
<p>The <directive>RewriteRule</directive> directive is the real
rewriting workhorse. The directive can occur more than once.
Each directive then defines one single rewriting rule. The
<strong>definition order</strong> of these rules is
<strong>important</strong>, because this order is used when
applying the rules at run-time.</p>
<p><a id="patterns" name="patterns"><em>Pattern</em></a> is
a perl compatible <a id="regexp" name="regexp">regular
expression</a> which gets applied to the current URL. Here
``current'' means the value of the URL when this rule gets
applied. This may not be the originally requested URL,
because any number of rules may already have matched and made
alterations to it.</p>
<p>Some hints about the syntax of regular expressions:</p>
<note><pre>
<strong>Text:</strong>
<strong><code>.</code></strong> Any single character
<strong><code>[</code></strong>chars<strong><code>]</code></strong> Character class: One of chars
<strong><code>[^</code></strong>chars<strong><code>]</code></strong> Character class: None of chars
text1<strong><code>|</code></strong>text2 Alternative: text1 or text2
<strong>Quantifiers:</strong>
<strong><code>?</code></strong> 0 or 1 of the preceding text
<strong><code>*</code></strong> 0 or N of the preceding text (N &gt; 0)
<strong><code>+</code></strong> 1 or N of the preceding text (N &gt; 1)
<strong>Grouping:</strong>
<strong><code>(</code></strong>text<strong><code>)</code></strong> Grouping of text
(either to set the borders of an alternative or
for making backreferences where the <strong>N</strong>th group can
be used on the RHS of a RewriteRule with <code>$</code><strong>N</strong>)
<strong>Anchors:</strong>
<strong><code>^</code></strong> Start of line anchor
<strong><code>$</code></strong> End of line anchor
<strong>Escaping:</strong>
<strong><code>\</code></strong>char escape that particular char
(for instance to specify the chars "<code>.[]()</code>" <em>etc.</em>)
</pre></note>
<p>For more information about regular expressions have a look at the
perl regular expression manpage ("<a
href="http://www.perldoc.com/perl5.6.1/pod/perlre.html">perldoc
perlre</a>"). If you are interested in more detailed
information about regular expressions and their variants
(POSIX regex <em>etc.</em>) have a look at the
following dedicated book on this topic:</p>
<p class="indent">
<em>Mastering Regular Expressions, 2nd Edition</em><br />
Jeffrey E.F. Friedl<br />
O'Reilly &amp; Associates, Inc. 2002<br />
ISBN 0-596-00289-0<br />
</p>
<p>Additionally in mod_rewrite the NOT character
('<code>!</code>') is a possible pattern prefix. This gives
you the ability to negate a pattern; to say, for instance:
``<em>if the current URL does <strong>NOT</strong> match this
pattern</em>''. This can be used for exceptional cases, where
it is easier to match the negative pattern, or as a last
default rule.</p>
<note><title>Notice</title>
When using the NOT character
to negate a pattern you cannot have grouped wildcard
parts in the pattern. This is impossible because when the
pattern does NOT match, there are no contents for the
groups. In consequence, if negated patterns are used, you
cannot use <code>$N</code> in the substitution
string!
</note>
<p><a id="rhs" name="rhs"><em>Substitution</em></a> of a
rewriting rule is the string which is substituted for (or
replaces) the original URL for which <em>Pattern</em>
matched. Beside plain text you can use</p>
<ol>
<li>back-references <code>$N</code> to the RewriteRule
pattern</li>
<li>back-references <code>%N</code> to the last matched
RewriteCond pattern</li>
<li>server-variables as in rule condition test-strings
(<code>%{VARNAME}</code>)</li>
<li><a href="#mapfunc">mapping-function</a> calls
(<code>${mapname:key|default}</code>)</li>
</ol>
<p>Back-references are <code>$</code><strong>N</strong>
(<strong>N</strong>=0..9) identifiers which will be replaced
by the contents of the <strong>N</strong>th group of the
matched <em>Pattern</em>. The server-variables are the same
as for the <em>TestString</em> of a <code>RewriteCond</code>
directive. The mapping-functions come from the
<code>RewriteMap</code> directive and are explained there.
These three types of variables are expanded in the order of
the above list. </p>
<p>As already mentioned above, all the rewriting rules are
applied to the <em>Substitution</em> (in the order of
definition in the config file). The URL is <strong>completely
replaced</strong> by the <em>Substitution</em> and the
rewriting process goes on until there are no more rules
unless explicitly terminated by a
<code><strong>L</strong></code> flag - see below.</p>
<p>There is a special substitution string named
'<code>-</code>' which means: <strong>NO
substitution</strong>! Sounds silly? No, it is useful to
provide rewriting rules which <strong>only</strong> match
some URLs but do no substitution, <em>e.g.</em>, in
conjunction with the <strong>C</strong> (chain) flag to be
able to have more than one pattern to be applied before a
substitution occurs.</p>
<note><title>Query String</title>
<p>The <em>Pattern</em> will not match against the query string.
Instead, you must use a <directive
module="mod_rewrite">RewriteCond</directive> with the
<code>%{QUERY_STRING}</code> variable. You can, however, create
URLs in the substitution string containing a query string
part. Just use a question mark inside the substitution string to
indicate that the following stuff should be re-injected into the
query string. When you want to erase an existing query string,
end the substitution string with just the question mark. To
combine a new query string with an old one, use the
<code>[QSA]</code> flag (see below).</p>
</note>
<note><title>Substitution of Absolute URLs</title>
<p>There is a special feature:
When you prefix a substitution field with
<code>http://</code><em>thishost</em>[<em>:thisport</em>]
then <strong>mod_rewrite</strong> automatically strips it
out. This auto-reduction on implicit external redirect
URLs is a useful and important feature when used in
combination with a mapping-function which generates the
hostname part. Have a look at the first example in the
example section below to understand this.</p>
<p><strong>Remember:</strong> An unconditional external
redirect to your own server will not work with the prefix
<code>http://thishost</code> because of this feature. To
achieve such a self-redirect, you have to use the
<strong>R</strong>-flag (see below).</p>
</note>
<p>Additionally you can set special <a name="rewriteflags"
id="rewriteflags">flags</a> for <em>Substitution</em> by
appending</p>
<p class="indent">
<strong><code>[</code><em>flags</em><code>]</code></strong>
</p>
<p>
as the third argument to the <code>RewriteRule</code>
directive. <em>Flags</em> is a comma-separated list of the
following flags: </p>
<ul>
<li>'<strong><code>chain|C</code></strong>'
(<strong>c</strong>hained with next rule)<br />
This flag chains the current rule with the next rule
(which itself can be chained with the following rule,
<em>etc.</em>). This has the following effect: if a rule
matches, then processing continues as usual, <em>i.e.</em>,
the flag has no effect. If the rule does
<strong>not</strong> match, then all following chained
rules are skipped. For instance, use it to remove the
``<code>.www</code>'' part inside a per-directory rule set
when you let an external redirect happen (where the
``<code>.www</code>'' part should not to occur!).</li>
<li>
'<strong><code>cookie|CO=</code></strong><em>NAME</em>:<em>VAL</em>:<em>domain</em>[:<em>lifetime</em>[:<em>path</em>]]'
(set <strong>co</strong>okie)<br />
This sets a cookie on the client's browser. The cookie's name
is specified by <em>NAME</em> and the value is
<em>VAL</em>. The <em>domain</em> field is the domain of the
cookie, such as '.apache.org',the optional <em>lifetime</em>
is the lifetime of the cookie in minutes, and the optional
<em>path</em> is the path of the cookie</li>
<li>
'<strong><code>env|E=</code></strong><em>VAR</em>:<em>VAL</em>'
(set <strong>e</strong>nvironment variable)<br />
This forces an environment variable named <em>VAR</em> to
be set to the value <em>VAL</em>, where <em>VAL</em> can
contain regexp backreferences <code>$N</code> and
<code>%N</code> which will be expanded. You can use this
flag more than once to set more than one variable. The
variables can be later dereferenced in many situations, but
usually from within XSSI (via <code>&lt;!--#echo
var="VAR"--&gt;</code>) or CGI (<em>e.g.</em>
<code>$ENV{'VAR'}</code>). Additionally you can dereference
it in a following RewriteCond pattern via
<code>%{ENV:VAR}</code>. Use this to strip but remember
information from URLs.</li>
<li>'<strong><code>forbidden|F</code></strong>' (force URL
to be <strong>f</strong>orbidden)<br />
This forces the current URL to be forbidden,
<em>i.e.</em>, it immediately sends back a HTTP response of
403 (FORBIDDEN). Use this flag in conjunction with
appropriate RewriteConds to conditionally block some
URLs.</li>
<li>'<strong><code>gone|G</code></strong>' (force URL to be
<strong>g</strong>one)<br />
This forces the current URL to be gone, <em>i.e.</em>, it
immediately sends back a HTTP response of 410 (GONE). Use
this flag to mark pages which no longer exist as gone.</li>
<li>
'<strong><code>handler|H</code></strong>=<em>Content-handler</em>'
(force Content <strong>h</strong>andler)<br />
Force the Content-handler of the target file to be
<em>Content-handler</em>. For instance, this can be used to
simulate the <code>mod_alias</code> directive
<code>ScriptAlias</code> which internally forces all files
inside the mapped directory to have a handler of
``<code>cgi-script</code>''.</li>
<li>'<strong><code>last|L</code></strong>'
(<strong>l</strong>ast rule)<br />
Stop the rewriting process here and don't apply any more
rewriting rules. This corresponds to the Perl
<code>last</code> command or the <code>break</code> command
from the C language. Use this flag to prevent the currently
rewritten URL from being rewritten further by following
rules. For example, use it to rewrite the root-path URL
('<code>/</code>') to a real one, <em>e.g.</em>,
'<code>/e/www/</code>'.</li>
<li>'<strong><code>next|N</code></strong>'
(<strong>n</strong>ext round)<br />
Re-run the rewriting process (starting again with the
first rewriting rule). Here the URL to match is again not
the original URL but the URL from the last rewriting rule.
This corresponds to the Perl <code>next</code> command or
the <code>continue</code> command from the C language. Use
this flag to restart the rewriting process, <em>i.e.</em>,
to immediately go to the top of the loop.<br />
<strong>But be careful not to create an infinite
loop!</strong></li>
<li>'<strong><code>nocase|NC</code></strong>'
(<strong>n</strong>o <strong>c</strong>ase)<br />
This makes the <em>Pattern</em> case-insensitive,
<em>i.e.</em>, there is no difference between 'A-Z' and
'a-z' when <em>Pattern</em> is matched against the current
URL.</li>
<li>
'<strong><code>noescape|NE</code></strong>'
(<strong>n</strong>o URI <strong>e</strong>scaping of
output)<br />
This flag keeps mod_rewrite from applying the usual URI
escaping rules to the result of a rewrite. Ordinarily,
special characters (such as '%', '$', ';', and so on)
will be escaped into their hexcode equivalents ('%25',
'%24', and '%3B', respectively); this flag prevents this
from being done. This allows percent symbols to appear in
the output, as in
<example>
RewriteRule /foo/(.*) /bar?arg=P1\%3d$1 [R,NE]
</example>
which would turn '<code>/foo/zed</code>' into a safe
request for '<code>/bar?arg=P1=zed</code>'.
</li>
<li>
'<strong><code>nosubreq|NS</code></strong>' (used only if
<strong>n</strong>o internal
<strong>s</strong>ub-request)<br />
This flag forces the rewriting engine to skip a
rewriting rule if the current request is an internal
sub-request. For instance, sub-requests occur internally
in Apache when <code>mod_include</code> tries to find out
information about possible directory default files
(<code>index.xxx</code>). On sub-requests it is not
always useful and even sometimes causes a failure to if
the complete set of rules are applied. Use this flag to
exclude some rules.<br />
<p>Use the following rule for your decision: whenever you
prefix some URLs with CGI-scripts to force them to be
processed by the CGI-script, the chance is high that you
will run into problems (or even overhead) on
sub-requests. In these cases, use this flag.</p>
</li>
<li>
'<strong><code>proxy|P</code></strong>' (force
<strong>p</strong>roxy)<br />
This flag forces the substitution part to be internally
forced as a proxy request and immediately (<em>i.e.</em>,
rewriting rule processing stops here) put through the <a
href="mod_proxy.html">proxy module</a>. You have to make
sure that the substitution string is a valid URI
(<em>e.g.</em>, typically starting with
<code>http://</code><em>hostname</em>) which can be
handled by the Apache proxy module. If not you get an
error from the proxy module. Use this flag to achieve a
more powerful implementation of the <a
href="mod_proxy.html#proxypass">ProxyPass</a> directive,
to map some remote stuff into the namespace of the local
server.
<p>Notice: To use this functionality make sure you have
the proxy module compiled into your Apache server
program. If you don't know please check whether
<code>mod_proxy.c</code> is part of the ``<code>httpd
-l</code>'' output. If yes, this functionality is
available to mod_rewrite. If not, then you first have to
rebuild the <program>httpd</program> program with mod_proxy
enabled.</p>
</li>
<li>
'<strong><code>passthrough|PT</code></strong>'
(<strong>p</strong>ass <strong>t</strong>hrough to next
handler)<br />
This flag forces the rewriting engine to set the
<code>uri</code> field of the internal
<code>request_rec</code> structure to the value of the
<code>filename</code> field. This flag is just a hack to
be able to post-process the output of
<code>RewriteRule</code> directives by
<code>Alias</code>, <code>ScriptAlias</code>,
<code>Redirect</code>, <em>etc.</em> directives from
other URI-to-filename translators. A trivial example to
show the semantics: If you want to rewrite
<code>/abc</code> to <code>/def</code> via the rewriting
engine of <code>mod_rewrite</code> and then
<code>/def</code> to <code>/ghi</code> with
<code>mod_alias</code>:
<example>
RewriteRule ^/abc(.*) /def$1 [PT]<br />
Alias /def /ghi
</example>
If you omit the <code>PT</code> flag then
<code>mod_rewrite</code> will do its job fine,
<em>i.e.</em>, it rewrites <code>uri=/abc/...</code> to
<code>filename=/def/...</code> as a full API-compliant
URI-to-filename translator should do. Then
<code>mod_alias</code> comes and tries to do a
URI-to-filename transition which will not work.
<p>Note: <strong>You have to use this flag if you want to
intermix directives of different modules which contain
URL-to-filename translators</strong>. The typical example
is the use of <code>mod_alias</code> and
<code>mod_rewrite</code>..</p>
</li>
<li>'<strong><code>qsappend|QSA</code></strong>'
(<strong>q</strong>uery <strong>s</strong>tring
<strong>a</strong>ppend)<br />
This flag forces the rewriting engine to append a query
string part in the substitution string to the existing one
instead of replacing it. Use this when you want to add more
data to the query string via a rewrite rule.</li>
<li>'<strong><code>redirect|R</code>
[=<em>code</em>]</strong>' (force <a id="redirect"
name="redirect"><strong>r</strong>edirect</a>)<br />
Prefix <em>Substitution</em> with
<code>http://thishost[:thisport]/</code> (which makes the
new URL a URI) to force a external redirection. If no
<em>code</em> is given a HTTP response of 302 (MOVED
TEMPORARILY) is used. If you want to use other response
codes in the range 300-400 just specify them as a number
or use one of the following symbolic names:
<code>temp</code> (default), <code>permanent</code>,
<code>seeother</code>. Use it for rules which should
canonicalize the URL and give it back to the client,
<em>e.g.</em>, translate ``<code>/~</code>'' into
``<code>/u/</code>'' or always append a slash to
<code>/u/</code><em>user</em>, etc.<br />
<p><strong>Note:</strong> When you use this flag, make
sure that the substitution field is a valid URL! If not,
you are redirecting to an invalid location! And remember
that this flag itself only prefixes the URL with
<code>http://thishost[:thisport]/</code>, rewriting
continues. Usually you also want to stop and do the
redirection immediately. To stop the rewriting you also
have to provide the 'L' flag.</p>
</li>
<li>'<strong><code>skip|S</code></strong>=<em>num</em>'
(<strong>s</strong>kip next rule(s))<br />
This flag forces the rewriting engine to skip the next
<em>num</em> rules in sequence when the current rule
matches. Use this to make pseudo if-then-else constructs:
The last rule of the then-clause becomes
<code>skip=N</code> where N is the number of rules in the
else-clause. (This is <strong>not</strong> the same as the
'chain|C' flag!)</li>
<li>
'<strong><code>type|T</code></strong>=<em>MIME-type</em>'
(force MIME <strong>t</strong>ype)<br />
Force the MIME-type of the target file to be
<em>MIME-type</em>. For instance, this can be used to
setup the content-type based on some conditions.
For example, the following snippet allows <code>.php</code> files to
be <em>displayed</em> by <code>mod_php</code> if they are called with
the <code>.phps</code> extension:
<example>
RewriteRule ^(.+\.php)s$ $1 [T=application/x-httpd-php-source]
</example>
</li>
</ul>
<note><title>Note</title> Never forget that <em>Pattern</em> is
applied to a complete URL in per-server configuration
files. <strong>But in per-directory configuration files, the
per-directory prefix (which always is the same for a specific
directory!) is automatically <em>removed</em> for the pattern matching
and automatically <em>added</em> after the substitution has been
done.</strong> This feature is essential for many sorts of rewriting,
because without this prefix stripping you have to match the parent
directory which is not always possible.
<p>There is one exception: If a substitution string
starts with ``<code>http://</code>'' then the directory
prefix will <strong>not</strong> be added and an
external redirect or proxy throughput (if flag
<strong>P</strong> is used!) is forced!</p>
</note>
<note><title>Note</title>
To enable the rewriting engine
for per-directory configuration files you need to set
``<code>RewriteEngine On</code>'' in these files
<strong>and</strong> ``<code>Options
FollowSymLinks</code>'' must be enabled. If your
administrator has disabled override of
<code>FollowSymLinks</code> for a user's directory, then
you cannot use the rewriting engine. This restriction is
needed for security reasons.
</note>
<p>Here are all possible substitution combinations and their
meanings:</p>
<p><strong>Inside per-server configuration
(<code>httpd.conf</code>)<br />
for request ``<code>GET
/somepath/pathinfo</code>'':</strong><br />
</p>
<note><pre>
<strong>Given Rule</strong> <strong>Resulting Substitution</strong>
---------------------------------------------- ----------------------------------
^/somepath(.*) otherpath$1 not supported, because invalid!
^/somepath(.*) otherpath$1 [R] not supported, because invalid!
^/somepath(.*) otherpath$1 [P] not supported, because invalid!
---------------------------------------------- ----------------------------------
^/somepath(.*) /otherpath$1 /otherpath/pathinfo
^/somepath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
via external redirection
^/somepath(.*) /otherpath$1 [P] not supported, because silly!
---------------------------------------------- ----------------------------------
^/somepath(.*) http://thishost/otherpath$1 /otherpath/pathinfo
^/somepath(.*) http://thishost/otherpath$1 [R] http://thishost/otherpath/pathinfo
via external redirection
^/somepath(.*) http://thishost/otherpath$1 [P] not supported, because silly!
---------------------------------------------- ----------------------------------
^/somepath(.*) http://otherhost/otherpath$1 http://otherhost/otherpath/pathinfo
via external redirection
^/somepath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfo
via external redirection
(the [R] flag is redundant)
^/somepath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfo
via internal proxy
</pre></note>
<p><strong>Inside per-directory configuration for
<code>/somepath</code><br />
(<em>i.e.</em>, file <code>.htaccess</code> in dir
<code>/physical/path/to/somepath</code> containing
<code>RewriteBase /somepath</code>)<br />
for request ``<code>GET
/somepath/localpath/pathinfo</code>'':</strong><br />
</p>
<note><pre>
<strong>Given Rule</strong> <strong>Resulting Substitution</strong>
---------------------------------------------- ----------------------------------
^localpath(.*) otherpath$1 /somepath/otherpath/pathinfo
^localpath(.*) otherpath$1 [R] http://thishost/somepath/otherpath/pathinfo
via external redirection
^localpath(.*) otherpath$1 [P] not supported, because silly!
---------------------------------------------- ----------------------------------
^localpath(.*) /otherpath$1 /otherpath/pathinfo
^localpath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
via external redirection
^localpath(.*) /otherpath$1 [P] not supported, because silly!
---------------------------------------------- ----------------------------------
^localpath(.*) http://thishost/otherpath$1 /otherpath/pathinfo
^localpath(.*) http://thishost/otherpath$1 [R] http://thishost/otherpath/pathinfo
via external redirection
^localpath(.*) http://thishost/otherpath$1 [P] not supported, because silly!
---------------------------------------------- ----------------------------------
^localpath(.*) http://otherhost/otherpath$1 http://otherhost/otherpath/pathinfo
via external redirection
^localpath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfo
via external redirection
(the [R] flag is redundant)
^localpath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfo
via internal proxy
</pre></note>
<p><strong>Example:</strong></p>
<p>We want to rewrite URLs of the form </p>
<p class="indent">
<code>/</code> <em>Language</em> <code>/~</code>
<em>Realname</em> <code>/.../</code> <em>File</em>
</p>
<p>into </p>
<p class="indent">
<code>/u/</code> <em>Username</em> <code>/.../</code>
<em>File</em> <code>.</code> <em>Language</em>
</p>
<p>We take the rewrite mapfile from above and save it under
<code>/path/to/file/map.txt</code>. Then we only have to
add the following lines to the Apache server configuration
file:</p>
<example>
<pre>
RewriteLog /path/to/file/rewrite.log
RewriteMap real-to-user txt:/path/to/file/map.txt
RewriteRule ^/([^/]+)/~([^/]+)/(.*)$ /u/${real-to-user:$2|nobody}/$3.$1
</pre>
</example>
</usage>
</directivesynopsis>
</modulesynopsis>