mod_rewrite.xml revision bf0e7f6393e91c0a7c15cb0d889a4238c973dc2e
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<!--
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding Licensed to the Apache Software Foundation (ASF) under one or more
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding contributor license agreements. See the NOTICE file distributed with
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding this work for additional information regarding copyright ownership.
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding The ASF licenses this file to You under the Apache License, Version 2.0
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding (the "License"); you may not use this file except in compliance with
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding the License. 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
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor<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>
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin <p>The <module>mod_rewrite</module> module uses a rule-based rewriting
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin engine, based on a regular-expression parser, to rewrite requested URLs on
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin the fly. By default, <module>mod_rewrite</module> maps a URL to a filesystem
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin path. However, it can also be used to redirect one URL to another URL, or
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin to invoke an internal proxy fetch.</p>
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin <p><module>mod_rewrite</module> provides a flexible and powerful way to
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin manipulate URLs using an unlimited number of rules. Each rule can have an
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin unlimited number of attached rule conditions, to allow you to rewrite URL
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin based on server variables, environment variables, HTTP headers, or time
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin stamps.</p>
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin <p><module>mod_rewrite</module> operates on the full URL path, including the
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin path-info section. A rewrite rule can be invoked in
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin <code>httpd.conf</code> or in <code>.htaccess</code>. The path generated
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin by a rewrite rule can include a query string, or can lead to internal
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin sub-processing, external request redirection, or internal proxy
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin 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
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
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor<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
4c36c711036219c80d5517d35be68a4769c15291slive <p>Note that rewrite configurations are not
4c36c711036219c80d5517d35be68a4769c15291slive inherited by virtual hosts. This means that you need to have a
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <code>RewriteEngine on</code> directive for each virtual host
4c36c711036219c80d5517d35be68a4769c15291slive in which you wish to use rewrite rules.</p>
fc9f416faa11879811f17d6efadedbf81cfd52a1covener
fc9f416faa11879811f17d6efadedbf81cfd52a1covener <p><directive>RewriteMap</directive> directives of the type <code>prg</code>
fc9f416faa11879811f17d6efadedbf81cfd52a1covener are not started during server initialization if they're defined in a
fc9f416faa11879811f17d6efadedbf81cfd52a1covener context that does not have <directive>RewriteEngine</directive> set to
fc9f416faa11879811f17d6efadedbf81cfd52a1covener <code>on</code></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
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor configuration. The <em>Option</em> string can currently
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin only be one of the following:</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
9ed9ba1fcf0a4a39f78f5f809c661bbd590b70eand <dl>
9ed9ba1fcf0a4a39f78f5f809c661bbd590b70eand <dt><code>inherit</code></dt>
9ed9ba1fcf0a4a39f78f5f809c661bbd590b70eand <dd>This forces the current configuration to inherit the
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin 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
a4d04b8c74044c58bd4182028a1408d936c95951covener <code>.htaccess</code> configuration or
a4d04b8c74044c58bd4182028a1408d936c95951covener <directive type="section" module="core">Directory</directive>
a4d04b8c74044c58bd4182028a1408d936c95951covener sections are inherited. The inherited rules are virtually copied
a4d04b8c74044c58bd4182028a1408d936c95951covener to the section where this directive is being used. If used in
a4d04b8c74044c58bd4182028a1408d936c95951covener combination with local rules, the inherited rules are copied behind
a4d04b8c74044c58bd4182028a1408d936c95951covener the local rules. The position of this directive - below or above
a4d04b8c74044c58bd4182028a1408d936c95951covener of local rules - has no influence on this behavior. If local
a4d04b8c74044c58bd4182028a1408d936c95951covener rules forced the rewriting to stop, the inherited rules won't
a4d04b8c74044c58bd4182028a1408d936c95951covener be processed.</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>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirindocument for details on how 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>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
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <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
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor 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
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor 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
9f7f8f89dfb9115b0b9493049a6ca1ecd8508242rbowen compile-time default will be chosen.</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
9f7f8f89dfb9115b0b9493049a6ca1ecd8508242rbowen <p>To create a dbm file from a source text file, use the <a
9f7f8f89dfb9115b0b9493049a6ca1ecd8508242rbowen href="/programs/httxt2dbm.html">httxt2dbm</a> utility.</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<example>
9f7f8f89dfb9115b0b9493049a6ca1ecd8508242rbowen$ httxt2dbm -i mapfile.txt -o mapfile.map
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive</example>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive </li>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <li>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <strong>Internal Function</strong><br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive MapType: <code>int</code>, MapSource: Internal Apache
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor function
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <p>Here, the source is an internal Apache function.
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive Currently you cannot create your own, but the following
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin functions already exist:</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <ul>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <li><strong>toupper</strong>:<br />
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Converts the key to all upper case.</li>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <li><strong>tolower</strong>:<br />
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Converts the key to all lower case.</li>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <li><strong>escape</strong>:<br />
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Translates special characters in the key to
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive hex-encodings.</li>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <li><strong>unescape</strong>:<br />
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Translates hex-encodings in the 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
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor path to valid regular file
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p>Here the source is a program, not a map file. To
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin create it you can use a language of your choice, but
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin the result has to be an executable program (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
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <p>This program is started once, when the Apache server
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin is started, and then communicates with the rewriting engine
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin via 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
a4d04b8c74044c58bd4182028a1408d936c95951covener is no corresponding value for the given key).</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
bf0e7f6393e91c0a7c15cb0d889a4238c973dc2etrawick <p>This feature utilizes the <code>rewrite-map</code> mutex,
bf0e7f6393e91c0a7c15cb0d889a4238c973dc2etrawick which is required for reliable communication with the program.
bf0e7f6393e91c0a7c15cb0d889a4238c973dc2etrawick The mutex mechanism and lock file can be configured with the
bf0e7f6393e91c0a7c15cb0d889a4238c973dc2etrawick <directive module="core">Mutex</directive> directive.</p>
bf0e7f6393e91c0a7c15cb0d889a4238c973dc2etrawick
63ef912b1ba017169e2623b3ad868aaef8d928e4covener <p>External rewriting programs are not started if they're defined in a
fc9f416faa11879811f17d6efadedbf81cfd52a1covener context that does not have <directive>RewriteEngine</directive> set to
fc9f416faa11879811f17d6efadedbf81cfd52a1covener <code>on</code></p>.
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor
a4d04b8c74044c58bd4182028a1408d936c95951covener <p>A trivial program which will implement a 1:1 map (<em>i.e.</em>,
a4d04b8c74044c58bd4182028a1408d936c95951covener key == value) could be:</p>
fc9f416faa11879811f17d6efadedbf81cfd52a1covener
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>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <li>``<em>Keep it simple, stupid</em>'' (KISS).
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor If this program hangs, it will cause Apache to hang
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi when trying to use the relevant rewrite rule.</li>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <li>A common mistake is to use buffered I/O on
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <code>stdout</code>. Avoid this, as it will cause a deadloop!
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin ``<code>$|=1</code>'' is used above, to prevent this.</li>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive </ol>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive </li>
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniq <li>
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniq <p><strong>SQL Query</strong><br />
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniq MapType: <code>dbd</code> or <code>fastdbd</code>,
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniq MapSource: An SQL SELECT statement that takes a single
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniq argument and returns a single value.</p>
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniq <p>This uses <module>mod_dbd</module> to implement a rewritemap
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniq by lookup in an SQL database. There are two forms:
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniq <code>fastdbd</code> caches database lookups internally,
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniq <code>dbd</code> doesn't. So <code>dbd</code> incurs a
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniq performance penalty but responds immediately if the database
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniq contents are updated, while <code>fastdbd</code> is more
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniq efficient but won't re-read database contents until server
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniq restart.</p>
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniq <p>If a query returns more than one row, a random row from
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniq the result set is used.</p>
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniq<example>
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniq<title>Example</title>
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniqRewriteMap myquery "fastdbd:SELECT destination FROM rewrite WHERE source = %s"
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniq</example>
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniq </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>
635de20c16ef862bfc5b0d5f9ceb40ebeaddfdf3noirin<default>None</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
25d988d92af8cf0d997aa1ebbc7cb11daa14d0becovener sets the base URL-path (not filesystem directory path!) for per-directory rewrites.
635de20c16ef862bfc5b0d5f9ceb40ebeaddfdf3noirin When you use a <directive module="mod_rewrite">RewriteRule</directive>
635de20c16ef862bfc5b0d5f9ceb40ebeaddfdf3noirin in a <code>.htaccess</code> file, <module>mod_rewrite</module> strips off
635de20c16ef862bfc5b0d5f9ceb40ebeaddfdf3noirin the local directory prefix before processing, then rewrites the rest of
635de20c16ef862bfc5b0d5f9ceb40ebeaddfdf3noirin the URL. When the rewrite is completed, <module>mod_rewrite</module>
635de20c16ef862bfc5b0d5f9ceb40ebeaddfdf3noirin automatically adds the local directory prefix back on to the path.</p>
635de20c16ef862bfc5b0d5f9ceb40ebeaddfdf3noirin
25d988d92af8cf0d997aa1ebbc7cb11daa14d0becovener <p>This directive is <em>required</em> for per-directory rewrites whose context
25d988d92af8cf0d997aa1ebbc7cb11daa14d0becovener is a directory made available via the <directive module="mod_alias">Alias</directive>
25d988d92af8cf0d997aa1ebbc7cb11daa14d0becovener directive.</p>
25d988d92af8cf0d997aa1ebbc7cb11daa14d0becovener
25d988d92af8cf0d997aa1ebbc7cb11daa14d0becovener <p>If your URL path does not exist verbatim on the filesystem,
25d988d92af8cf0d997aa1ebbc7cb11daa14d0becovener or isn't directly under your <directive module="core">DocumentRoot</directive>,
635de20c16ef862bfc5b0d5f9ceb40ebeaddfdf3noirin you must use <directive>RewriteBase</directive> in every
635de20c16ef862bfc5b0d5f9ceb40ebeaddfdf3noirin <code>.htaccess</code> file where you want to use <directive
25d988d92af8cf0d997aa1ebbc7cb11daa14d0becovener module="mod_rewrite">RewriteRule</directive> directives.</p>
635de20c16ef862bfc5b0d5f9ceb40ebeaddfdf3noirin
635de20c16ef862bfc5b0d5f9ceb40ebeaddfdf3noirin <p>The example below demonstrates how to map
25d988d92af8cf0d997aa1ebbc7cb11daa14d0becovener <code>http://example.com/myapp/index.html</code> to
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin <code>/home/www/example/newsite.html</code>, in a <code>.htaccess</code>
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin file. This assumes that the content available at
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin <code>http://example.com/</code> is on disk at
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin <code>/home/www/example/</code>.</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<example>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<pre>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfsliveRewriteEngine On
25d988d92af8cf0d997aa1ebbc7cb11daa14d0becovener# The URL-path used to get to this context, not the filesystem path
25d988d92af8cf0d997aa1ebbc7cb11daa14d0becovenerRewriteBase /myapp/
635de20c16ef862bfc5b0d5f9ceb40ebeaddfdf3noirinRewriteRule ^index\.html$ newsite.html
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive</pre>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive</example>
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>
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin <p>The <directive module="mod_rewrite">RewriteCond</directive>
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin directive defines a rule condition. One or more <directive
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin module="mod_rewrite">RewriteCond</directive>
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin conditions can precede a <directive module="mod_rewrite"
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin >RewriteRule</directive> directive. The following rewrite rule is then
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin used only if these conditions are met, and if the URI matches the pattern
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin specified in the rule.</p>
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin <section id="TestString">
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin <title>TestString</title>
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin <p><code><em>TestString</em></code> can contain plain text, any of the
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin following expanded constructs, or both.</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <ul>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <li>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <strong>RewriteRule backreferences</strong>: These are
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin backreferences of the form <strong><code>$N</code></strong>
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin (1 &lt;= N &lt;= 9). They provide access to the grouped
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin parts of the current <code>RewriteRule</code> pattern. The grouped
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin parts of the pattern are those in parentheses.</li>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <li>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <strong>RewriteCond backreferences</strong>: These are
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin backreferences of the form <strong><code>%N</code></strong>
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin (1 &lt;= N &lt;= 9). They provide access to the grouped
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin parts of the last-matched <code>RewriteCond</code> pattern. The
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin grouped parts of the pattern are those in parentheses.</li>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <li>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <strong>RewriteMap expansions</strong>: These are
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin expansions of the form <strong><code
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi >${mapname:key|default}</code></strong>.
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin See the <a href="#mapfunc">RewriteMap documentation</a>
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin for more details.
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive </li>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <li>
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin <strong>Server variables</strong>: These are variables of
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor the form
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin <strong><code>%{ <em>NAME_OF_VARIABLE</em> }</code></strong>,
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin where <em>NAME_OF_VARIABLE</em> is one of the server variables from
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin the table below:
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin <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>
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi </tr>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele <tr>
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi <td>
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi 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>
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi <td></td>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive </tr>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <tr>
53d2fd50ff45e7c568f0588c742a5ef9edf8e275rbowen <th>server internals:</th> <th>date and time:</th> <th>specials:</th>
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi </tr>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele <tr>
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi <td>
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi 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>
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin </li></ul>
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin <note><p>The following variables are specific to
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin <module>mod_rewrite</module>:</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <dl>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <dt><code>IS_SUBREQ</code></dt>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin <dd>Contains the text "true" if the request
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin currently being processed is a sub-request, or
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
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin <dd>The version of the Apache module API contained in the
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin current httpd build, as defined in
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin include/ap_mmn.h.</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
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin line.</dd>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <dt><code>REQUEST_FILENAME</code></dt>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin <dd>The full local filesystem path of the file or
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive script matching the request.</dd>
7748a5c411233f9e1f3df10ea5fffffa91e58824jorton
7748a5c411233f9e1f3df10ea5fffffa91e58824jorton <dt><code>HTTPS</code></dt>
7748a5c411233f9e1f3df10ea5fffffa91e58824jorton
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin <dd>Contains the text "on" if the connection is
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin using SSL/TLS, or "off" otherwise. This variable
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin does not depend on <module>mod_ssl</module> being loaded.</dd>
7748a5c411233f9e1f3df10ea5fffffa91e58824jorton
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive </dl>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive</note>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin <p>Note that the <code>SCRIPT_FILENAME</code> and
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin <code>REQUEST_FILENAME</code>
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin variables both contain the value of the
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <code>filename</code> field of the internal
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin <code>request_rec</code> structure.
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin If a substitution occurs and rewriting continues,
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin the value of both variables will be updated accordingly.
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin In a per-server context, before the
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin request is mapped to the filesystem, these variables contain the value
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin of <code>REQUEST_URI</code>, because the full filesystem path is not
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin yet known. To obtain the full filesystem
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin path of a request in a per-server context, use a URL-based
a4d04b8c74044c58bd4182028a1408d936c95951covener look-ahead <code>%{LA-U:REQUEST_FILENAME}</code> to determine
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin the final value of <code>REQUEST_FILENAME</code>.</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin <p>Other available variables include the following:</p>
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin <ul><li>
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin <code>%{ENV:<em>variable</em>}</code>, where <em>variable</em> can be
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin any environment variable.</li>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <li>
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin <code>%{SSL:<em>variable</em>}</code>, where <em>variable</em> is the
7748a5c411233f9e1f3df10ea5fffffa91e58824jorton name of an <a href="mod_ssl.html#envvars">SSL environment
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin variable</a>. If <module>mod_ssl</module> is not loaded, this
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin will always expand to the empty string.</li>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <li>
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin <code>%{HTTP:<em>header</em>}</code>, where <em>header</em> can be
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin any HTTP MIME-header name. For example,
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin <code>%{HTTP:Proxy-Connection}</code> is the value of the HTTP header
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin ``<code>Proxy-Connection:</code>''. If a HTTP header is used in a
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin condition, and the condition evaluates to <code>true</code>, then that
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin header is added to the Vary header of the response. This is used to
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin ensure proper caching.
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin If a previous condition has evaluated to <code>true</code> and the
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin '<strong><code>ornext|OR</code></strong>' flag is in use, later
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin conditions are not evaluated, and therefore headers are not added to the
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin Vary header.</li>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <li>
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin <code>%{LA-U:<em>variable</em>}</code>, which is used to perform
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin an internal URL-based sub-request, to determine the final
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin value of <em>variable</em>. This can be used to access the value of
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin a variable which is to be set in a later phase. For example, the
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin <code>REMOTE_USER</code> variable is set in the authorization phase of
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin processing. This comes after the URL translation phase, where rewrite
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin rules in <code>httpd.conf</code> are applied, but before the fixup
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin phase, where rewrite rules in a <code>.htaccess</code> file are applied.
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin Therefore, to obtain the value of the <code>REMOTE_USER</code> variable
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin within <code>httpd.conf</code>, you must use <code
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin >%{LA-U:REMOTE_USER}</code>. To obtain the value of the
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin <code>REMOTE_USER</code> variable within a <code>.htaccess</code> file,
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin simply use <code>%{REMOTE_USER}</code></li>
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin </ul>
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin </section>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin <section id="CondPattern">
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin <title>CondPattern</title>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p><em>CondPattern</em> is the condition pattern,
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin a regular expression which is applied to the
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin current instance of the <em>TestString</em>.
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <em>TestString</em> is first evaluated, before being 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
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor use one of the following:
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <ul>
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor <li>'<strong>&lt;CondPattern</strong>' (lexicographically
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi precedes)<br />
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Treats the <em>CondPattern</em> as a plain string and
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin compares it lexicographically to <em>TestString</em>. True if
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <em>TestString</em> lexicographically precedes
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <em>CondPattern</em>.</li>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <li>'<strong>&gt;CondPattern</strong>' (lexicographically
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin follows)<br />
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Treats the <em>CondPattern</em> as a plain string and
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin compares it lexicographically to <em>TestString</em>. True if
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <em>TestString</em> lexicographically follows
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <em>CondPattern</em>.</li>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <li>'<strong>=CondPattern</strong>' (lexicographically
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive equal)<br />
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Treats the <em>CondPattern</em> as a plain string and
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin compares it lexicographically to <em>TestString</em>. True if
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <em>TestString</em> is lexicographically equal to
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <em>CondPattern</em> (the two strings are exactly
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin equal, character for character). If <em>CondPattern</em>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin is <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
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin whether or not 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
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin whether or not it exists, and is a regular file.</li>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <li>'<strong>-s</strong>' (is regular file, with
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <strong>s</strong>ize)<br />
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Treats the <em>TestString</em> as a pathname and tests
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin whether or not 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 />
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Treats the <em>TestString</em> as a pathname and tests
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin whether or not 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
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor whether or not it exists, and has executable permissions.
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor These permissions are determined according to
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi the underlying OS.</li>
4e3cdb85620921a8a120fe22edbccae708f4f34end
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <li>'<strong>-F</strong>' (is existing file, via
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive subrequest)<br />
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Checks whether or not <em>TestString</em> is a valid file,
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive accessible via all the server's currently-configured
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive access controls for that path. This uses an internal
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin subrequest to do the check, so use it with care -
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin it can impact your server's performance!</li>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <li>'<strong>-U</strong>' (is existing URL, via
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive subrequest)<br />
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Checks whether or not <em>TestString</em> is a valid URL,
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive accessible via all the server's currently-configured
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive access controls for that path. This uses an internal
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor subrequest to do the check, so use it with care -
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin it can impact your server's performance!</li>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive </ul>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin<note><title>Note:</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
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi <li>You can also set special flags for
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <em>CondPattern</em> by appending
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <strong><code>[</code><em>flags</em><code>]</code></strong>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin as the third argument to the <code>RewriteCond</code>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin directive, where <em>flags</em> is a comma-separated list of any of the
5a4ba75a85817ca324e4f054d56f42a6a14adc5dnd following flags:
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <ul>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <li>'<strong><code>nocase|NC</code></strong>'
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive (<strong>n</strong>o <strong>c</strong>ase)<br />
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor This makes the test case-insensitive - differences
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi between 'A-Z' and 'a-z' are ignored, 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 />
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Use this to combine rule conditions with a local OR
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor 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
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Without this flag you would have to write the condition/rule
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin pair three times.
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive </li>
b65a184929c97d0b0e4d3bad42648e0e9ce1b8ferpluem
b65a184929c97d0b0e4d3bad42648e0e9ce1b8ferpluem <li>'<strong><code>novary|NV</code></strong>'
b65a184929c97d0b0e4d3bad42648e0e9ce1b8ferpluem (<strong>n</strong>o <strong>v</strong>ary)<br />
b65a184929c97d0b0e4d3bad42648e0e9ce1b8ferpluem If a HTTP header is used in the condition, this flag prevents
b65a184929c97d0b0e4d3bad42648e0e9ce1b8ferpluem this header from being added to the Vary header of the response. <br />
b65a184929c97d0b0e4d3bad42648e0e9ce1b8ferpluem Using this flag might break proper caching of the response if
b65a184929c97d0b0e4d3bad42648e0e9ce1b8ferpluem the representation of this response varies on the value of this header.
b65a184929c97d0b0e4d3bad42648e0e9ce1b8ferpluem So this flag should be only used if the meaning of the Vary header
b65a184929c97d0b0e4d3bad42648e0e9ce1b8ferpluem is well understood.
b65a184929c97d0b0e4d3bad42648e0e9ce1b8ferpluem </li>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive </ul>
5a4ba75a85817ca324e4f054d56f42a6a14adc5dnd </li>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin </ol>
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
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor <p>Explanation: If you use a browser which identifies itself
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi as 'Mozilla' (including Netscape Navigator, Mozilla etc), then you
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin get the max homepage (which could include frames, or other special
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi features).
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin If you use the Lynx browser (which is terminal-based), then
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor you get the min homepage (which could be a version designed for
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi easy, text-only browsing).
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi If neither of these conditions apply (you use any other browser,
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi or your browser identifies itself as something non-standard), you get
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin the std (standard) homepage.</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
1fdfe3acc7d9000fcc4c5bfab678f361873f674bnoirin</section>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive</usage>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive</directivesynopsis>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<directivesynopsis>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<name>RewriteRule</name>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<description>Defines rules for the rewriting engine</description>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<syntax>RewriteRule
96147932f199be4ad038778e702c13a2f79051c0slive <em>Pattern</em> <em>Substitution</em> [<em>flags</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>RewriteRule</directive> directive is the real
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor rewriting workhorse. The directive can occur more than once,
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin with each instance defining a single rewrite rule. The
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin order in which these rules are defined is important - this is the order
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin in which they will be applied 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
a4d04b8c74044c58bd4182028a1408d936c95951covener expression</a>. On the first RewriteRule it is applied to the (%-encoded)
8c8c2e71c84babf0e8c4b35819c7c5b3be014cfenoodl <a href="/directive-dict.html#Syntax">URL-path</a> of the request;
8c8c2e71c84babf0e8c4b35819c7c5b3be014cfenoodl subsequent patterns are applied to the output of the last matched
8c8c2e71c84babf0e8c4b35819c7c5b3be014cfenoodl RewriteRule.</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
96147932f199be4ad038778e702c13a2f79051c0slive<note><title>What is matched?</title>
96147932f199be4ad038778e702c13a2f79051c0slive <p>The <em>Pattern</em> will initially be matched against the part of the
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener URL after the hostname and port, and before the query string.</p>
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener <p>When the RewriteRule appears in per-directory (htaccess) context, the
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener <em>Pattern</em> is matched against what remains of the URL after removing
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener the prefix that lead Apache to the current rules (see the
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener <directive module="mod_rewrite">RewriteBase</directive>). The removed prefix
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener always ends with a slash, meaning the matching occurs against a string which
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener never has a leading slash. A <em>Pattern</em> with <code>^/</code> never
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener matches in per-directory context.</p>
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener <p>If you wish to match against the hostname, port, or query string, use a
96147932f199be4ad038778e702c13a2f79051c0slive <directive module="mod_rewrite">RewriteCond</directive> with the
96147932f199be4ad038778e702c13a2f79051c0slive <code>%{HTTP_HOST}</code>, <code>%{SERVER_PORT}</code>, or
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener <code>%{QUERY_STRING}</code> variables respectively. If you wish to
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener match against the full URL-path in a per-directory (htaccess) RewriteRule,
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener use the <code>%{REQUEST_URI}</code> variable.</p>
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener
96147932f199be4ad038778e702c13a2f79051c0slive</note>
96147932f199be4ad038778e702c13a2f79051c0slive
70f2730533c8592263435354e66d9dbaf4d6361bslive <p>For some hints on <glossary ref="regex">regular
70f2730533c8592263435354e66d9dbaf4d6361bslive expressions</glossary>, see
1093a264c81aa1041581ab059905fb8f7cdfc5e2rbowen the <a href="/rewrite/intro.html#regex">mod_rewrite
70f2730533c8592263435354e66d9dbaf4d6361bslive Introduction</a>.</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi <p>In mod_rewrite, the NOT character
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor ('<code>!</code>') is also available as a possible pattern
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin prefix. This enables you 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
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin<note><title>Note</title>
5f18f92c1354462df6dc2ba38277a953fa700b13gryzorWhen using the NOT character to negate a pattern, you cannot include
5f18f92c1354462df6dc2ba38277a953fa700b13gryzorgrouped wildcard parts in that pattern. This is because, when the
5f18f92c1354462df6dc2ba38277a953fa700b13gryzorpattern does NOT match (ie, the negation matches), there are no
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirincontents for the groups. Thus, if negated patterns are used, you
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirincannot use <code>$N</code> in the substitution string!
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive</note>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
96147932f199be4ad038778e702c13a2f79051c0slive <p>The <a id="rhs" name="rhs"><em>Substitution</em></a> of a
96147932f199be4ad038778e702c13a2f79051c0slive rewrite rule is the string that replaces the original URL-path that
96147932f199be4ad038778e702c13a2f79051c0slive was matched by <em>Pattern</em>. The <em>Substitution</em> may
96147932f199be4ad038778e702c13a2f79051c0slive be a:</p>
96147932f199be4ad038778e702c13a2f79051c0slive
96147932f199be4ad038778e702c13a2f79051c0slive <dl>
96147932f199be4ad038778e702c13a2f79051c0slive
96147932f199be4ad038778e702c13a2f79051c0slive <dt>file-system path</dt>
96147932f199be4ad038778e702c13a2f79051c0slive
96147932f199be4ad038778e702c13a2f79051c0slive <dd>Designates the location on the file-system of the resource
96147932f199be4ad038778e702c13a2f79051c0slive to be delivered to the client.</dd>
96147932f199be4ad038778e702c13a2f79051c0slive
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor <dt>URL-path</dt>
96147932f199be4ad038778e702c13a2f79051c0slive
96147932f199be4ad038778e702c13a2f79051c0slive <dd>A <directive
96147932f199be4ad038778e702c13a2f79051c0slive module="core">DocumentRoot</directive>-relative path to the
96147932f199be4ad038778e702c13a2f79051c0slive resource to be served. Note that <module>mod_rewrite</module>
96147932f199be4ad038778e702c13a2f79051c0slive tries to guess whether you have specified a file-system path
45309cf90ecc60d20e1ac810881e7b149fbe4e35noodl or a URL-path by checking to see if the first segment of the
96147932f199be4ad038778e702c13a2f79051c0slive path exists at the root of the file-system. For example, if
96147932f199be4ad038778e702c13a2f79051c0slive you specify a <em>Substitution</em> string of
96147932f199be4ad038778e702c13a2f79051c0slive <code>/www/file.html</code>, then this will be treated as a
96147932f199be4ad038778e702c13a2f79051c0slive URL-path <em>unless</em> a directory named <code>www</code>
96147932f199be4ad038778e702c13a2f79051c0slive exists at the root or your file-system, in which case it will
96147932f199be4ad038778e702c13a2f79051c0slive be treated as a file-system path. If you wish other
96147932f199be4ad038778e702c13a2f79051c0slive URL-mapping directives (such as <directive
96147932f199be4ad038778e702c13a2f79051c0slive module="mod_alias">Alias</directive>) to be applied to the
96147932f199be4ad038778e702c13a2f79051c0slive resulting URL-path, use the <code>[PT]</code> flag as
96147932f199be4ad038778e702c13a2f79051c0slive described below.</dd>
96147932f199be4ad038778e702c13a2f79051c0slive
96147932f199be4ad038778e702c13a2f79051c0slive <dt>Absolute URL</dt>
96147932f199be4ad038778e702c13a2f79051c0slive
96147932f199be4ad038778e702c13a2f79051c0slive <dd>If an absolute URL is specified,
96147932f199be4ad038778e702c13a2f79051c0slive <module>mod_rewrite</module> checks to see whether the
96147932f199be4ad038778e702c13a2f79051c0slive hostname matches the current host. If it does, the scheme and
96147932f199be4ad038778e702c13a2f79051c0slive hostname are stripped out and the resulting path is treated as
96147932f199be4ad038778e702c13a2f79051c0slive a URL-path. Otherwise, an external redirect is performed for
96147932f199be4ad038778e702c13a2f79051c0slive the given URL. To force an external redirect back to the
96147932f199be4ad038778e702c13a2f79051c0slive current host, see the <code>[R]</code> flag below.</dd>
96147932f199be4ad038778e702c13a2f79051c0slive
96147932f199be4ad038778e702c13a2f79051c0slive <dt><code>-</code> (dash)</dt>
96147932f199be4ad038778e702c13a2f79051c0slive
96147932f199be4ad038778e702c13a2f79051c0slive <dd>A dash indicates that no substitution should be performed
96147932f199be4ad038778e702c13a2f79051c0slive (the existing path is passed through untouched). This is used
96147932f199be4ad038778e702c13a2f79051c0slive when a flag (see below) needs to be applied without changing
96147932f199be4ad038778e702c13a2f79051c0slive the path.</dd>
96147932f199be4ad038778e702c13a2f79051c0slive
96147932f199be4ad038778e702c13a2f79051c0slive </dl>
96147932f199be4ad038778e702c13a2f79051c0slive
96147932f199be4ad038778e702c13a2f79051c0slive <p>In addition to plain text, the <em>Substition</em> string can include</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <ol>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <li>back-references (<code>$N</code>) to the RewriteRule
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive pattern</li>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <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>
96147932f199be4ad038778e702c13a2f79051c0slive
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor <p>Back-references are identifiers of the form
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi <code>$</code><strong>N</strong>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin (<strong>N</strong>=0..9), 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.
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin These three types of variables are expanded in the order above.</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <p>As already mentioned, all rewrite rules are
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor applied to the <em>Substitution</em> (in the order in which
4bf4c38816cd24dab6fee4884ee98b58011cb6a5noirin they are defined
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin in the config file). The URL is <strong>completely
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive replaced</strong> by the <em>Substitution</em> and the
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin rewriting process continues until all rules have been applied,
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin or it is explicitly terminated by a
4bf4c38816cd24dab6fee4884ee98b58011cb6a5noirin <code><strong>L</strong></code> flag.</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
96147932f199be4ad038778e702c13a2f79051c0slive <note><title>Modifying the Query String</title>
96147932f199be4ad038778e702c13a2f79051c0slive <p>By default, the query string is passed through unchanged. You
96147932f199be4ad038778e702c13a2f79051c0slive can, however, create URLs in the substitution string containing
96147932f199be4ad038778e702c13a2f79051c0slive a query string part. Simply use a question mark inside the
96147932f199be4ad038778e702c13a2f79051c0slive substitution string to indicate that the following text should
96147932f199be4ad038778e702c13a2f79051c0slive be re-injected into the query string. When you want to erase an
96147932f199be4ad038778e702c13a2f79051c0slive existing query string, end the substitution string with just a
96147932f199be4ad038778e702c13a2f79051c0slive question mark. To combine new and old query strings, use the
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor <code>[QSA]</code> flag.</p>
96147932f199be4ad038778e702c13a2f79051c0slive </note>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
ff21ab9f1cc3037fe58a2029432834581594b6c4pctony
21f4ac5ab80abe4cbe90ae0f340c29053556c52drbowen <p>Additionally you can set special <a name="rewriteflags"
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor id="rewriteflags">actions</a> to be performed by
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin appending <strong><code>[</code><em>flags</em><code>]</code></strong>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive as the third argument to the <code>RewriteRule</code>
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor directive. <em>Flags</em> is a comma-separated list, surround by square
96147932f199be4ad038778e702c13a2f79051c0slive brackets, of any of the following flags: </p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
8a571abb6573d916da05fc8b9f04fd944ad45803slive <dl>
5ff68527ed4cfc34ba93eb201b79fc3363ee66e4niq <dt>'<code>B</code>' (escape backreferences)</dt>
5ff68527ed4cfc34ba93eb201b79fc3363ee66e4niq <dd><p>Apache has to unescape URLs before mapping them,
5ff68527ed4cfc34ba93eb201b79fc3363ee66e4niq so backreferences will be unescaped at the time they are applied.
5ff68527ed4cfc34ba93eb201b79fc3363ee66e4niq Using the B flag, non-alphanumeric characters in backreferences
df920f9fde6e219311c85b8a01e0104943eb594and will be escaped. For example, consider the rule:</p>
a4d04b8c74044c58bd4182028a1408d936c95951covener <example>
a4d04b8c74044c58bd4182028a1408d936c95951covener RewriteRule ^(/.*)$ /index.php?show=$1
a4d04b8c74044c58bd4182028a1408d936c95951covener </example>
df920f9fde6e219311c85b8a01e0104943eb594and <p>This will map <code>/C++</code> to
df920f9fde6e219311c85b8a01e0104943eb594and <code>/index.php?show=/C++</code>. But it will also map
df920f9fde6e219311c85b8a01e0104943eb594and <code>/C%2b%2b</code> to <code>/index.php?show=/C++</code>, because
df920f9fde6e219311c85b8a01e0104943eb594and the <code>%2b</code> has been unescaped. With the B flag, it will
df920f9fde6e219311c85b8a01e0104943eb594and instead map to <code>/index.php?show=/C%2b%2b</code>.</p>
5ff68527ed4cfc34ba93eb201b79fc3363ee66e4niq <p>This escaping is particularly necessary in a proxy situation,
5ff68527ed4cfc34ba93eb201b79fc3363ee66e4niq when the backend may break if presented with an unescaped URL.</p>
5ff68527ed4cfc34ba93eb201b79fc3363ee66e4niq </dd>
5ff68527ed4cfc34ba93eb201b79fc3363ee66e4niq
8a571abb6573d916da05fc8b9f04fd944ad45803slive <dt>'<code>chain|C</code>'
8a571abb6573d916da05fc8b9f04fd944ad45803slive (chained with next rule)</dt><dd>
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen This flag chains the current rule with the next rule
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen (which itself can be chained with the following rule,
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin and so on). This has the following effect: if a rule
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor matches, then processing continues as usual -
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen the flag has no effect. If the rule does
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen <strong>not</strong> match, then all following chained
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin rules are skipped. For instance, it can be used to remove the
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin ``<code>.www</code>'' part, inside a per-directory rule set,
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen when you let an external redirect happen (where the
8a571abb6573d916da05fc8b9f04fd944ad45803slive ``<code>.www</code>'' part should not occur!).</dd>
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen
06d3a46db9574ad55b65fed36b856fee72bd71a7rpluem <dt>'<code>cookie|CO=</code><em>NAME</em>:<em>VAL</em>:<em>domain</em>[:<em>lifetime</em>[:<em>path</em>[:<em>secure</em>[:<em>httponly</em>]]]]'
8a571abb6573d916da05fc8b9f04fd944ad45803slive (set cookie)</dt><dd>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin This sets a cookie in 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
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin cookie, such as '.apache.org', the optional <em>lifetime</em>
8ee58d1690f3d354f136e70181b78b9dc63f4312rpluem is the lifetime of the cookie in minutes (0 means expires at end
8ee58d1690f3d354f136e70181b78b9dc63f4312rpluem of session), and the optional
06d3a46db9574ad55b65fed36b856fee72bd71a7rpluem <em>path</em> is the path of the cookie. If <em>secure</em>
5d43ff13e733c78683f05d920116d194110aa097rpluem is set to 'secure', 'true' or '1', the cookie is only transmitted via secured
5d43ff13e733c78683f05d920116d194110aa097rpluem connections. If <em>httponly</em> is set to 'HttpOnly', 'true' or '1', the
13f6fce2a15f2e2d7ecd7ee9734bfe9cb40db6cenoodl <code>HttpOnly</code> flag is used, making the cookie inaccessible
06d3a46db9574ad55b65fed36b856fee72bd71a7rpluem to JavaScript code on browsers that support this feature.</dd>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
1464434c2c104e0ba224644c42552330f5158537covener <dt>'<code>discardpathinfo|DPI'
1464434c2c104e0ba224644c42552330f5158537covener (discard PATH_INFO)</code></dt><dd>
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor <p>This flag is available from 2.2.12</p>
1464434c2c104e0ba224644c42552330f5158537covener <p>In per-directory context, the URI each <directive>RewriteRule</directive>
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor compares against is the concatenation of the current values of the URI
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor and PATH_INFO.</p>
1464434c2c104e0ba224644c42552330f5158537covener
1464434c2c104e0ba224644c42552330f5158537covener <p>The current URI can be the initial URI as requested by the client, the
907c2e66b6ee3e080cb51db0573b19983efce358covener result of a previous round of mod_rewrite processing, or the result of
1464434c2c104e0ba224644c42552330f5158537covener a prior rule in the current round of mod_rewrite processing.</p>
1464434c2c104e0ba224644c42552330f5158537covener
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor <p>In contrast, the PATH_INFO that is appended to the URI before each
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor rule reflects only the value of PATH_INFO before this round of
1464434c2c104e0ba224644c42552330f5158537covener mod_rewrite processing. As a consequence, if large portions
1464434c2c104e0ba224644c42552330f5158537covener of the URI are matched and copied into a substitution in multiple
1464434c2c104e0ba224644c42552330f5158537covener <directive>RewriteRule</directive> directives, without regard for
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor which parts of the URI came from the current PATH_INFO, the final
1464434c2c104e0ba224644c42552330f5158537covener URI may have multiple copies of PATH_INFO appended to it.</p>
1464434c2c104e0ba224644c42552330f5158537covener
1464434c2c104e0ba224644c42552330f5158537covener <p>Use this flag on any substitution where the PATH_INFO that resulted
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor from the previous mapping of this request to the filesystem is not of
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor interest. This flag permanently forgets the PATH_INFO established
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor before this round of mod_rewrite processing began. PATH_INFO will
1464434c2c104e0ba224644c42552330f5158537covener not be recalculated until the current round of mod_rewrite processing
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor completes. Subsequent rules during this round of processing will see
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor only the direct result of substitutions, without any PATH_INFO
1464434c2c104e0ba224644c42552330f5158537covener appended.</p></dd>
1464434c2c104e0ba224644c42552330f5158537covener
8a571abb6573d916da05fc8b9f04fd944ad45803slive <dt>
8a571abb6573d916da05fc8b9f04fd944ad45803slive '<code>env|E=</code><em>VAR</em>:<em>VAL</em>'
8a571abb6573d916da05fc8b9f04fd944ad45803slive (set environment variable)</dt><dd>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin This forces an environment variable named <em>VAR</em> to
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen be set to the value <em>VAL</em>, where <em>VAL</em> can
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin contain regexp backreferences (<code>$N</code> and
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <code>%N</code>) which will be expanded. You can use this
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin flag more than once, to set more than one variable. The
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin variables can later be dereferenced in many situations, most commonly
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi from within XSSI (via <code>&lt;!--#echo
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor var="VAR"--&gt;</code>) or CGI (<code>$ENV{'VAR'}</code>).
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi You can also dereference the variable in a later RewriteCond pattern, using
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor <code>%{ENV:VAR}</code>. Use this to strip
8a571abb6573d916da05fc8b9f04fd944ad45803slive information from URLs, while maintaining a record of that information.</dd>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
8a571abb6573d916da05fc8b9f04fd944ad45803slive <dt>'<code>forbidden|F</code>' (force URL
8a571abb6573d916da05fc8b9f04fd944ad45803slive to be forbidden)</dt><dd>
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor This forces the current URL to be forbidden - it immediately
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor sends back a HTTP response of 403 (FORBIDDEN).
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi Use this flag in conjunction with
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive appropriate RewriteConds to conditionally block some
8a571abb6573d916da05fc8b9f04fd944ad45803slive URLs.</dd>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
8a571abb6573d916da05fc8b9f04fd944ad45803slive <dt>'<code>gone|G</code>' (force URL to be
8a571abb6573d916da05fc8b9f04fd944ad45803slive gone)</dt><dd>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin This forces the current URL to be gone - it
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive immediately sends back a HTTP response of 410 (GONE). Use
8a571abb6573d916da05fc8b9f04fd944ad45803slive this flag to mark pages which no longer exist as gone.</dd>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
8a571abb6573d916da05fc8b9f04fd944ad45803slive <dt>
8a571abb6573d916da05fc8b9f04fd944ad45803slive '<code>handler|H</code>=<em>Content-handler</em>'
8a571abb6573d916da05fc8b9f04fd944ad45803slive (force Content handler)</dt><dd>
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen Force the Content-handler of the target file to be
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen <em>Content-handler</em>. For instance, this can be used to
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin simulate the <module>mod_alias</module> directive
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor <directive module="mod_alias">ScriptAlias</directive>,
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi which internally forces all files
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen inside the mapped directory to have a handler of
a4d04b8c74044c58bd4182028a1408d936c95951covener ``<code>cgi-script</code>''.<br />
a4d04b8c74044c58bd4182028a1408d936c95951covener If used in per-directory context, there must not be a substitution
a4d04b8c74044c58bd4182028a1408d936c95951covener which changes the path. Use this flag in per-directory context only
a4d04b8c74044c58bd4182028a1408d936c95951covener with <code>-</code> (dash) as the substitution, otherwise the request
a4d04b8c74044c58bd4182028a1408d936c95951covener will fail.</dd>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
8a571abb6573d916da05fc8b9f04fd944ad45803slive <dt>'<code>last|L</code>'
8a571abb6573d916da05fc8b9f04fd944ad45803slive (last rule)</dt><dd> Stop the rewriting process
8ed0917f332087770872e032b248b2e1e689df3bslive here and don't apply any more rewrite rules. This corresponds
8ed0917f332087770872e032b248b2e1e689df3bslive to the Perl <code>last</code> command or the
8ed0917f332087770872e032b248b2e1e689df3bslive <code>break</code> command in C. Use this flag to prevent the
8ed0917f332087770872e032b248b2e1e689df3bslive currently rewritten URL from being rewritten further by
8ed0917f332087770872e032b248b2e1e689df3bslive following rules. Remember, however, that if the
8ed0917f332087770872e032b248b2e1e689df3bslive <directive>RewriteRule</directive> generates an internal
8ed0917f332087770872e032b248b2e1e689df3bslive redirect (which frequently occurs when rewriting in a
8ed0917f332087770872e032b248b2e1e689df3bslive per-directory context), this will reinject the request and
8ed0917f332087770872e032b248b2e1e689df3bslive will cause processing to be repeated starting from the first
8a571abb6573d916da05fc8b9f04fd944ad45803slive <directive>RewriteRule</directive>.</dd>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
8a571abb6573d916da05fc8b9f04fd944ad45803slive <dt>'<code>next|N</code>'
8a571abb6573d916da05fc8b9f04fd944ad45803slive (next round)</dt><dd>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Re-run the rewriting process (starting again with the
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin first rewriting rule). This time, the URL to match is no longer
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin the original URL, but rather the URL returned by the last rewriting rule.
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive This corresponds to the Perl <code>next</code> command or
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin the <code>continue</code> command in C. Use
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin this flag to restart the rewriting process -
8a571abb6573d916da05fc8b9f04fd944ad45803slive to immediately go to the top of the loop.
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <strong>Be careful not to create an infinite
8a571abb6573d916da05fc8b9f04fd944ad45803slive loop!</strong></dd>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
8a571abb6573d916da05fc8b9f04fd944ad45803slive <dt>'<code>nocase|NC</code>'
8a571abb6573d916da05fc8b9f04fd944ad45803slive (no case)</dt><dd>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin This makes the <em>Pattern</em> case-insensitive,
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin ignoring difference between 'A-Z' and
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen 'a-z' when <em>Pattern</em> is matched against the current
8a571abb6573d916da05fc8b9f04fd944ad45803slive URL.</dd>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
8a571abb6573d916da05fc8b9f04fd944ad45803slive <dt>
8a571abb6573d916da05fc8b9f04fd944ad45803slive '<code>noescape|NE</code>'
8a571abb6573d916da05fc8b9f04fd944ad45803slive (no URI escaping of
8a571abb6573d916da05fc8b9f04fd944ad45803slive output)</dt><dd>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin This flag prevents 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
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin from happening. This allows percent symbols to appear in
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor the output, as in
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen<example>
a4d04b8c74044c58bd4182028a1408d936c95951covener RewriteRule ^/foo/(.*) /bar?arg=P1\%3d$1 [R,NE]
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen</example>
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen which would turn '<code>/foo/zed</code>' into a safe
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor request for '<code>/bar?arg=P1=zed</code>'.
8a571abb6573d916da05fc8b9f04fd944ad45803slive </dd>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
8a571abb6573d916da05fc8b9f04fd944ad45803slive <dt>
8a571abb6573d916da05fc8b9f04fd944ad45803slive '<code>nosubreq|NS</code>'
8a571abb6573d916da05fc8b9f04fd944ad45803slive (not for internal
8a571abb6573d916da05fc8b9f04fd944ad45803slive sub-requests)</dt><dd>
8a571abb6573d916da05fc8b9f04fd944ad45803slive <p>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
a4d04b8c74044c58bd4182028a1408d936c95951covener in Apache when <module>mod_dir</module> tries to find out
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive information about possible directory default files
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin (<code>index.xxx</code> files). On sub-requests it is not
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin always useful, and can even cause errors, if
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive the complete set of rules are applied. Use this flag to
8a571abb6573d916da05fc8b9f04fd944ad45803slive exclude some rules.</p>
8a571abb6573d916da05fc8b9f04fd944ad45803slive <p>To decide whether or not to use this rule: if you
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin prefix URLs with CGI-scripts, to force them to be
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor processed by the CGI-script, it's likely that you
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin will run into problems (or significant overhead) on
8a571abb6573d916da05fc8b9f04fd944ad45803slive sub-requests. In these cases, use this flag.</p>
8a571abb6573d916da05fc8b9f04fd944ad45803slive </dd>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
8a571abb6573d916da05fc8b9f04fd944ad45803slive <dt>
8a571abb6573d916da05fc8b9f04fd944ad45803slive '<code>proxy|P</code>' (force
8a571abb6573d916da05fc8b9f04fd944ad45803slive proxy)</dt><dd>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin This flag forces the substitution part to be internally
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor sent as a proxy request and immediately (rewrite
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi processing stops here) put through the <a
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin href="mod_proxy.html">proxy module</a>. You must make
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen sure that the substitution string is a valid URI
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin (typically starting with
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen <code>http://</code><em>hostname</em>) which can be
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin handled by the Apache proxy module. If not, you will 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,
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin to map remote content into the namespace of the local
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor server.
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <p>Note: <module>mod_proxy</module> must be enabled in order
9b82bd7c7f2083318e7856831dede324534308bcrbowen to use this flag.</p>
8a571abb6573d916da05fc8b9f04fd944ad45803slive </dd>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
8a571abb6573d916da05fc8b9f04fd944ad45803slive <dt>
8a571abb6573d916da05fc8b9f04fd944ad45803slive '<code>passthrough|PT</code>'
8a571abb6573d916da05fc8b9f04fd944ad45803slive (pass through to next
8a571abb6573d916da05fc8b9f04fd944ad45803slive handler)</dt><dd>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin This flag forces the rewrite 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
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin enable post-processing of the output of
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <code>RewriteRule</code> directives, using
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <code>Alias</code>, <code>ScriptAlias</code>,
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <code>Redirect</code>, and other directives from
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin various URI-to-filename translators. For example, to rewrite
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <code>/abc</code> to <code>/def</code> using
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <module>mod_rewrite</module>, and then
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <code>/def</code> to <code>/ghi</code> using
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor <module>mod_alias</module>:
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<example>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive RewriteRule ^/abc(.*) /def$1 [PT]<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive Alias /def /ghi
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive</example>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin If you omit the <code>PT</code> flag,
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin <module>mod_rewrite</module> will rewrite
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi <code>uri=/abc/...</code> to
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <code>filename=/def/...</code> as a full API-compliant
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive URI-to-filename translator should do. Then
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <code>mod_alias</code> will try to do a
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor URI-to-filename transition, which will fail.
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <p>Note: <strong>You must use this flag if you want to
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin mix directives from different modules which allow
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive URL-to-filename translators</strong>. The typical example
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin is the use of <module>mod_alias</module> and
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <module>mod_rewrite</module>.</p>
b5407b0669a6a7175c84859e727d133399e4fa51slive
b5407b0669a6a7175c84859e727d133399e4fa51slive <p>The <code>PT</code> flag implies the <code>L</code> flag:
b5407b0669a6a7175c84859e727d133399e4fa51slive rewriting will be stopped in order to pass the request to
b5407b0669a6a7175c84859e727d133399e4fa51slive the next phase of processing.</p>
8a571abb6573d916da05fc8b9f04fd944ad45803slive </dd>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
8a571abb6573d916da05fc8b9f04fd944ad45803slive <dt>'<code>qsappend|QSA</code>'
8a571abb6573d916da05fc8b9f04fd944ad45803slive (query string
8a571abb6573d916da05fc8b9f04fd944ad45803slive append)</dt><dd>
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener This flag forces the rewrite engine to append the query
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener string part of the substitution string to the existing query string,
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen instead of replacing it. Use this when you want to add more
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener data to the query string via a rewrite rule. This rule has no net effect
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener unless your substitution explicitly provides a new query string.</dd>
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen
8a571abb6573d916da05fc8b9f04fd944ad45803slive <dt>'<code>redirect|R</code>
8a571abb6573d916da05fc8b9f04fd944ad45803slive [=<em>code</em>]' (force <a id="redirect"
8a571abb6573d916da05fc8b9f04fd944ad45803slive name="redirect">redirect</a>)</dt><dd>
8a571abb6573d916da05fc8b9f04fd944ad45803slive <p>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
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <em>code</em> is given, a HTTP response of 302 (MOVED
8a571abb6573d916da05fc8b9f04fd944ad45803slive TEMPORARILY) will be returned. If you want to use other
8a571abb6573d916da05fc8b9f04fd944ad45803slive response codes, simply specify the appropriate number or use
8a571abb6573d916da05fc8b9f04fd944ad45803slive one of the following symbolic names: <code>temp</code>
8a571abb6573d916da05fc8b9f04fd944ad45803slive (default), <code>permanent</code>,
8a571abb6573d916da05fc8b9f04fd944ad45803slive <code>seeother</code>. Use this for rules to canonicalize
8a571abb6573d916da05fc8b9f04fd944ad45803slive the URL and return it to the client - to translate
8a571abb6573d916da05fc8b9f04fd944ad45803slive ``<code>/~</code>'' into ``<code>/u/</code>'', or to always
8a571abb6573d916da05fc8b9f04fd944ad45803slive append a slash to <code>/u/</code><em>user</em>, etc.<br />
8a571abb6573d916da05fc8b9f04fd944ad45803slive <strong>Note:</strong> When you use this flag, make sure
8a571abb6573d916da05fc8b9f04fd944ad45803slive that the substitution field is a valid URL! Otherwise, you
8a571abb6573d916da05fc8b9f04fd944ad45803slive will be redirecting to an invalid location. Remember that
8a571abb6573d916da05fc8b9f04fd944ad45803slive this flag on its own will only prepend
8a571abb6573d916da05fc8b9f04fd944ad45803slive <code>http://thishost[:thisport]/</code> to the URL, and
8a571abb6573d916da05fc8b9f04fd944ad45803slive rewriting will continue. Usually, you will want to stop
8a571abb6573d916da05fc8b9f04fd944ad45803slive rewriting at this point, and redirect immediately. To stop
8a571abb6573d916da05fc8b9f04fd944ad45803slive rewriting, you should add the 'L' flag.</p>
758cbf6f938a9e5b39422509d1e39b7078c1a1dcslive <p>While this is typically used for redirects, any valid status
758cbf6f938a9e5b39422509d1e39b7078c1a1dcslive code can be given here. If the status code is outside the redirect
758cbf6f938a9e5b39422509d1e39b7078c1a1dcslive range (300-399), then the <em>Substitution</em> string is dropped
758cbf6f938a9e5b39422509d1e39b7078c1a1dcslive and rewriting is stopped as if the <code>L</code> flag was
758cbf6f938a9e5b39422509d1e39b7078c1a1dcslive used.</p>
8a571abb6573d916da05fc8b9f04fd944ad45803slive </dd>
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen
8a571abb6573d916da05fc8b9f04fd944ad45803slive <dt>'<code>skip|S</code>=<em>num</em>'
8a571abb6573d916da05fc8b9f04fd944ad45803slive (skip next rule(s))</dt><dd>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin This flag forces the rewriting engine to skip the next
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <em>num</em> rules in sequence, if the current rule
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive matches. Use this to make pseudo if-then-else constructs:
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive The last rule of the then-clause becomes
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <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
8a571abb6573d916da05fc8b9f04fd944ad45803slive 'chain|C' flag!)</dd>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
8a571abb6573d916da05fc8b9f04fd944ad45803slive <dt>
8a571abb6573d916da05fc8b9f04fd944ad45803slive '<code>type|T</code>=<em>MIME-type</em>'
8a571abb6573d916da05fc8b9f04fd944ad45803slive (force MIME type)</dt><dd>
c14037646789087319802aaada2e8534ccab0158slive Force the <glossary>MIME-type</glossary> of the target file to be
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <em>MIME-type</em>. This can be used to
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin set up the content-type based on some conditions.
a4d04b8c74044c58bd4182028a1408d936c95951covener If used in per-directory context, use only <code>-</code> (dash)
a4d04b8c74044c58bd4182028a1408d936c95951covener as the substitution, otherwise the MIME-type set with this flag
a4d04b8c74044c58bd4182028a1408d936c95951covener is lost due to an internal re-processing.</dd>
8a571abb6573d916da05fc8b9f04fd944ad45803slive </dl>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
ff21ab9f1cc3037fe58a2029432834581594b6c4pctony
de68ca33425122cf4a880859013e08e84f8143a5covener<note><title>Home directory expansion</title>
de68ca33425122cf4a880859013e08e84f8143a5covener<p> When the substitution string begins with a string
de68ca33425122cf4a880859013e08e84f8143a5covenerresembling "/~user" (via explicit text or backreferences), mod_rewrite performs
5f18f92c1354462df6dc2ba38277a953fa700b13gryzorhome directory expansion independent of the presence or configuration
4e6d765a1b53690664877065e6b6c741c1b96937covenerof <module>mod_userdir</module>.</p>
de68ca33425122cf4a880859013e08e84f8143a5covener
de68ca33425122cf4a880859013e08e84f8143a5covener<p> This expansion does not occur when the <em>PT</em>
de68ca33425122cf4a880859013e08e84f8143a5covenerflag is used on the <directive module="mod_rewrite">RewriteRule</directive>
de68ca33425122cf4a880859013e08e84f8143a5covenerdirective.</p>
de68ca33425122cf4a880859013e08e84f8143a5covener</note>
de68ca33425122cf4a880859013e08e84f8143a5covener
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslive<note><title>Per-directory Rewrites</title>
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslive<p>The rewrite engine may be used in <a
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslivehref="/howto/htaccess.html">.htaccess</a> files. To enable the
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcsliverewrite engine for these files you need to set
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslive"<code>RewriteEngine On</code>" <strong>and</strong>
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslive"<code>Options FollowSymLinks</code>" must be enabled. If your
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcsliveadministrator has disabled override of <code>FollowSymLinks</code> for
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslivea user's directory, then you cannot use the rewrite engine. This
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcsliverestriction is required for security reasons.</p>
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslive
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslive<p>When using the rewrite engine in <code>.htaccess</code> files the
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfsliveper-directory prefix (which always is the same for a specific
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirindirectory) is automatically <em>removed</em> for the pattern matching
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfsliveand automatically <em>added</em> after the substitution has been
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslivedone. This feature is essential for many sorts of rewriting; without
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslivethis, you would always have to match the parent directory, which is
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslivenot always possible. There is one exception: If a substitution string
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslivestarts with <code>http://</code>, then the directory prefix will
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslive<strong>not</strong> be added, and an external redirect (or proxy
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslivethroughput, if using flag <strong>P</strong>) is forced. See the
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslive<directive module="mod_rewrite">RewriteBase</directive> directive for
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslivemore information.</p>
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslive
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslive<p>The rewrite engine may also be used in <directive type="section"
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslivemodule="core">Directory</directive> sections with the same
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcsliveprefix-matching rules as would be applied to <code>.htaccess</code>
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslivefiles. It is usually simpler, however, to avoid the prefix substitution
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslivecomplication by putting the rewrite rules in the main server or
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslivevirtual host context, rather than in a <directive type="section"
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslivemodule="core">Directory</directive> section.</p>
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslive
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslive<p>Although rewrite rules are syntactically permitted in <directive
a4d04b8c74044c58bd4182028a1408d936c95951covenertype="section" module="core">Location</directive> and <directive
a4d04b8c74044c58bd4182028a1408d936c95951covenertype="section" module="core">Files</directive> sections, this
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcsliveshould never be necessary and is unsupported.</p>
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslive
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive</note>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <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---------------------------------------------- ----------------------------------
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin^/somepath(.*) otherpath$1 invalid, not supported
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin^/somepath(.*) otherpath$1 [R] invalid, not supported
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin^/somepath(.*) otherpath$1 [P] invalid, not supported
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive---------------------------------------------- ----------------------------------
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive^/somepath(.*) /otherpath$1 /otherpath/pathinfo
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive^/somepath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive via external redirection
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin^/somepath(.*) /otherpath$1 [P] doesn't make sense, not supported
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
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin^/somepath(.*) http://thishost/otherpath$1 [P] doesn't make sense, not supported
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 />
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin (<code>/physical/path/to/somepath/.htacccess</code>, with
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <code>RewriteBase /somepath</code>)<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive for request ``<code>GET
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor /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
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin^localpath(.*) otherpath$1 [P] doesn't make sense, not supported
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive---------------------------------------------- ----------------------------------
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive^localpath(.*) /otherpath$1 /otherpath/pathinfo
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive^localpath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive via external redirection
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin^localpath(.*) /otherpath$1 [P] doesn't make sense, not supported
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
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin^localpath(.*) http://thishost/otherpath$1 [P] doesn't make sense, not supported
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>
013e1ddd21f2142a369c9a9a0eeb6c6a0bc3fcf3patrikj </usage>
013e1ddd21f2142a369c9a9a0eeb6c6a0bc3fcf3patrikj </directivesynopsis>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive</modulesynopsis>