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