mod_rewrite.xml revision 8a571abb6573d916da05fc8b9f04fd944ad45803
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<?xml version="1.0"?>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<!DOCTYPE modulesynopsis SYSTEM "/style/modulesynopsis.dtd">
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<!-- $LastChangedRevision$ -->
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<!--
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor Licensed to the Apache Software Foundation (ASF) under one or more
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor contributor license agreements. See the NOTICE file distributed with
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor this work for additional information regarding copyright ownership.
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor The ASF licenses this file to You under the Apache License, Version 2.0
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen (the "License"); you may not use this file except in compliance with
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen the License. You may obtain a copy of the License at
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen http://www.apache.org/licenses/LICENSE-2.0
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor Unless required by applicable law or agreed to in writing, software
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor distributed under the License is distributed on an "AS IS" BASIS,
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3f08db06526d6901aa08c110b5bc7dde6bc39905nd See the License for the specific language governing permissions and
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor limitations under the License.
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor-->
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
3f08db06526d6901aa08c110b5bc7dde6bc39905nd<modulesynopsis metafile="mod_rewrite.xml.meta">
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<name>mod_rewrite</name>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<description>Provides a rule-based rewriting engine to rewrite requested
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjungURLs on the fly</description>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<status>Extension</status>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<sourcefile>mod_rewrite.c</sourcefile>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<identifier>rewrite_module</identifier>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<compatibility>Available in Apache 1.3 and later</compatibility>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<summary>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <p>This module uses a rule-based rewriting engine (based on a
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor regular-expression parser) to rewrite requested URLs on the
c867dba1041640ecec7c8194d35a5b4ffce442earbowen fly. It supports an unlimited number of rules and an
c867dba1041640ecec7c8194d35a5b4ffce442earbowen unlimited number of attached rule conditions for each rule, to
b71e5eae594d54e9e56dc20208c6a7fb52610e29rbowen provide a really flexible and powerful URL manipulation
c867dba1041640ecec7c8194d35a5b4ffce442earbowen mechanism. The URL manipulations can depend on various tests,
c867dba1041640ecec7c8194d35a5b4ffce442earbowen of server variables, environment variables, HTTP
c867dba1041640ecec7c8194d35a5b4ffce442earbowen headers, or time stamps. Even external database lookups in
c867dba1041640ecec7c8194d35a5b4ffce442earbowen various formats can be used to achieve highly granular URL
c867dba1041640ecec7c8194d35a5b4ffce442earbowen matching.</p>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <p>This module operates on the full URLs (including the
c867dba1041640ecec7c8194d35a5b4ffce442earbowen path-info part) both in per-server context
c867dba1041640ecec7c8194d35a5b4ffce442earbowen (<code>httpd.conf</code>) and per-directory context
c867dba1041640ecec7c8194d35a5b4ffce442earbowen (<code>.htaccess</code>) and can generate query-string
c867dba1041640ecec7c8194d35a5b4ffce442earbowen parts on result. The rewritten result can lead to internal
c867dba1041640ecec7c8194d35a5b4ffce442earbowen sub-processing, external request redirection or even to an
c867dba1041640ecec7c8194d35a5b4ffce442earbowen internal proxy throughput.</p>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <p>Further details, discussion, and examples, are provided in the
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <a href="/rewrite/">detailed mod_rewrite documentation</a>.</p>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen</summary>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<section id="quoting"><title>Quoting Special Characters</title>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <p>As of Apache 1.3.20, special characters in
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <em>TestString</em> and <em>Substitution</em> strings can be
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor escaped (that is, treated as normal characters without their
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor usual special meaning) by prefixing them with a slash ('\')
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor character. In other words, you can include an actual
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor dollar-sign character in a <em>Substitution</em> string by
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor using '<code>\$</code>'; this keeps mod_rewrite from trying
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor to treat it as a backreference.</p>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</section>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<section id="EnvVar"><title>Environment Variables</title>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <p>This module keeps track of two additional (non-standard)
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor CGI/SSI environment variables named <code>SCRIPT_URL</code>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen and <code>SCRIPT_URI</code>. These contain the
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh <em>logical</em> Web-view to the current resource, while the
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor standard CGI/SSI variables <code>SCRIPT_NAME</code> and
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <code>SCRIPT_FILENAME</code> contain the <em>physical</em>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen System-view. </p>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <p>Notice: These variables hold the URI/URL <em>as they were
c867dba1041640ecec7c8194d35a5b4ffce442earbowen initially requested</em>, that is, <em>before</em> any
c867dba1041640ecec7c8194d35a5b4ffce442earbowen rewriting. This is important to note because the rewriting process is
c867dba1041640ecec7c8194d35a5b4ffce442earbowen primarily used to rewrite logical URLs to physical
c867dba1041640ecec7c8194d35a5b4ffce442earbowen pathnames.</p>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<example><title>Example</title>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<pre>
c867dba1041640ecec7c8194d35a5b4ffce442earbowenSCRIPT_NAME=/sw/lib/w3s/tree/global/u/rse/.www/index.html
c867dba1041640ecec7c8194d35a5b4ffce442earbowenSCRIPT_FILENAME=/u/rse/.www/index.html
c867dba1041640ecec7c8194d35a5b4ffce442earbowenSCRIPT_URL=/u/rse/
c867dba1041640ecec7c8194d35a5b4ffce442earbowenSCRIPT_URI=http://en1.engelschall.com/u/rse/
c867dba1041640ecec7c8194d35a5b4ffce442earbowen</pre>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen</example>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
fe2be2903c65e2f99f04199655ea5f97a75825d0humbedooh</section>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
fe2be2903c65e2f99f04199655ea5f97a75825d0humbedooh<section id="vhosts"><title>Rewriting in Virtual Hosts</title>
fe2be2903c65e2f99f04199655ea5f97a75825d0humbedooh
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <p>By default, <module>mod_rewrite</module> configuration
c867dba1041640ecec7c8194d35a5b4ffce442earbowen settings from the main server context are not inherited by
c867dba1041640ecec7c8194d35a5b4ffce442earbowen virtual hosts. To make the main server settings apply to virtual
c867dba1041640ecec7c8194d35a5b4ffce442earbowen hosts, you must place the following directives in each <directive
c867dba1041640ecec7c8194d35a5b4ffce442earbowen module="core" type="section">VirtualHost</directive> section:</p>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <example>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen RewriteEngine On<br />
c867dba1041640ecec7c8194d35a5b4ffce442earbowen RewriteOptions Inherit
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor </example>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen</section>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<section id="Solutions"><title>Practical Solutions</title>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <p>For numerous examples of common, and not-so-common, uses for
c867dba1041640ecec7c8194d35a5b4ffce442earbowen mod_rewrite, see the <a href="/rewrite/rewrite_guide.html">Rewrite
c867dba1041640ecec7c8194d35a5b4ffce442earbowen Guide</a>, and the <a
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor href="/rewrite/rewrite_guide_advanced.html">Advanced Rewrite
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor Guide</a> documents.</p>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</section>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<directivesynopsis>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<name>RewriteEngine</name>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<description>Enables or disables runtime rewriting engine</description>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<syntax>RewriteEngine on|off</syntax>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<default>RewriteEngine off</default>
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen<contextlist><context>server config</context><context>virtual host</context>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<context>directory</context><context>.htaccess</context></contextlist>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<override>FileInfo</override>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
16055ce2030d5a9ab3b1797dfe4ba2c1177a6af9nd<usage>
16055ce2030d5a9ab3b1797dfe4ba2c1177a6af9nd
16055ce2030d5a9ab3b1797dfe4ba2c1177a6af9nd <p>The <directive>RewriteEngine</directive> directive enables or
16055ce2030d5a9ab3b1797dfe4ba2c1177a6af9nd disables the runtime rewriting engine. If it is set to
16055ce2030d5a9ab3b1797dfe4ba2c1177a6af9nd <code>off</code> this module does no runtime processing at
16055ce2030d5a9ab3b1797dfe4ba2c1177a6af9nd all. It does not even update the <code>SCRIPT_URx</code>
16055ce2030d5a9ab3b1797dfe4ba2c1177a6af9nd environment variables.</p>
16055ce2030d5a9ab3b1797dfe4ba2c1177a6af9nd
16055ce2030d5a9ab3b1797dfe4ba2c1177a6af9nd <p>Use this directive to disable the module instead of
16055ce2030d5a9ab3b1797dfe4ba2c1177a6af9nd commenting out all the <directive
16055ce2030d5a9ab3b1797dfe4ba2c1177a6af9nd module="mod_rewrite">RewriteRule</directive> directives!</p>
16055ce2030d5a9ab3b1797dfe4ba2c1177a6af9nd
16055ce2030d5a9ab3b1797dfe4ba2c1177a6af9nd <p>Note that rewrite configurations are not
16055ce2030d5a9ab3b1797dfe4ba2c1177a6af9nd inherited by virtual hosts. This means that you need to have a
16055ce2030d5a9ab3b1797dfe4ba2c1177a6af9nd <code>RewriteEngine on</code> directive for each virtual host
16055ce2030d5a9ab3b1797dfe4ba2c1177a6af9nd in which you wish to use rewrite rules.</p>
16055ce2030d5a9ab3b1797dfe4ba2c1177a6af9nd</usage>
16055ce2030d5a9ab3b1797dfe4ba2c1177a6af9nd
16055ce2030d5a9ab3b1797dfe4ba2c1177a6af9nd</directivesynopsis>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
16055ce2030d5a9ab3b1797dfe4ba2c1177a6af9nd<directivesynopsis>
16055ce2030d5a9ab3b1797dfe4ba2c1177a6af9nd<name>RewriteOptions</name>
16055ce2030d5a9ab3b1797dfe4ba2c1177a6af9nd<description>Sets some special options for the rewrite engine</description>
16055ce2030d5a9ab3b1797dfe4ba2c1177a6af9nd<syntax>RewriteOptions <var>Options</var></syntax>
16055ce2030d5a9ab3b1797dfe4ba2c1177a6af9nd<contextlist><context>server config</context><context>virtual host</context>
16055ce2030d5a9ab3b1797dfe4ba2c1177a6af9nd<context>directory</context><context>.htaccess</context></contextlist>
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf<override>FileInfo</override>
fe2be2903c65e2f99f04199655ea5f97a75825d0humbedooh<compatibility><code>MaxRedirects</code> is no longer available in version 2.1 and
16055ce2030d5a9ab3b1797dfe4ba2c1177a6af9ndlater</compatibility>
16055ce2030d5a9ab3b1797dfe4ba2c1177a6af9nd<usage>
16055ce2030d5a9ab3b1797dfe4ba2c1177a6af9nd
fe2be2903c65e2f99f04199655ea5f97a75825d0humbedooh <p>The <directive>RewriteOptions</directive> directive sets some
fe2be2903c65e2f99f04199655ea5f97a75825d0humbedooh special options for the current per-server or per-directory
fe2be2903c65e2f99f04199655ea5f97a75825d0humbedooh configuration. The <em>Option</em> string can currently
16055ce2030d5a9ab3b1797dfe4ba2c1177a6af9nd only be one of the following:</p>
fe2be2903c65e2f99f04199655ea5f97a75825d0humbedooh
fe2be2903c65e2f99f04199655ea5f97a75825d0humbedooh <dl>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <dt><code>inherit</code></dt>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <dd>This forces the current configuration to inherit the
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor configuration of the parent. In per-virtual-server context,
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor this means that the maps, conditions and rules of the main
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor server are inherited. In per-directory context this means
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor that conditions and rules of the parent directory's
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <code>.htaccess</code> configuration are inherited.</dd>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor </dl>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</usage>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</directivesynopsis>
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<directivesynopsis>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<name>RewriteLog</name>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<description>Sets the name of the file used for logging rewrite engine
c867dba1041640ecec7c8194d35a5b4ffce442earbowenprocessing</description>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<syntax>RewriteLog <em>file-path</em></syntax>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<contextlist><context>server config</context><context>virtual host</context>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen</contextlist>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<usage>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <p>The <directive>RewriteLog</directive> directive sets the name
c867dba1041640ecec7c8194d35a5b4ffce442earbowen of the file to which the server logs any rewriting actions it
c867dba1041640ecec7c8194d35a5b4ffce442earbowen performs. If the name does not begin with a slash
c867dba1041640ecec7c8194d35a5b4ffce442earbowen ('<code>/</code>') then it is assumed to be relative to the
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf <em>Server Root</em>. The directive should occur only once per
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor server config.</p>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<note> To disable the logging of
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor rewriting actions it is not recommended to set
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <em>Filename</em> to <code>/dev/null</code>, because
c867dba1041640ecec7c8194d35a5b4ffce442earbowen although the rewriting engine does not then output to a
c867dba1041640ecec7c8194d35a5b4ffce442earbowen logfile it still creates the logfile output internally.
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <strong>This will slow down the server with no advantage
c867dba1041640ecec7c8194d35a5b4ffce442earbowen to the administrator!</strong> To disable logging either
c867dba1041640ecec7c8194d35a5b4ffce442earbowen remove or comment out the <directive>RewriteLog</directive>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor directive or use <code>RewriteLogLevel 0</code>!
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</note>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<note type="securitywarning"><title>Security</title>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowenSee the <a href="/misc/security_tips.html">Apache Security Tips</a>
c867dba1041640ecec7c8194d35a5b4ffce442earbowendocument for details on how your security could be compromised if the
c867dba1041640ecec7c8194d35a5b4ffce442earbowendirectory where logfiles are stored is writable by anyone other than
c867dba1041640ecec7c8194d35a5b4ffce442earbowenthe user that starts the server.
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</note>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<example><title>Example</title>
c867dba1041640ecec7c8194d35a5b4ffce442earbowenRewriteLog "/usr/local/var/apache/logs/rewrite.log"
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</example>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</usage>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
c867dba1041640ecec7c8194d35a5b4ffce442earbowen</directivesynopsis>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<directivesynopsis>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<name>RewriteLogLevel</name>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<description>Sets the verbosity of the log file used by the rewrite
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzorengine</description>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<syntax>RewriteLogLevel <em>Level</em></syntax>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<default>RewriteLogLevel 0</default>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<contextlist><context>server config</context><context>virtual host</context>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</contextlist>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<usage>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <p>The <directive>RewriteLogLevel</directive> directive sets the
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor verbosity level of the rewriting logfile. The default level 0
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor means no logging, while 9 or more means that practically all
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor actions are logged.</p>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <p>To disable the logging of rewriting actions simply set
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <em>Level</em> to 0. This disables all rewrite action
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor logs.</p>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<note> Using a high value for
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <em>Level</em> will slow down your Apache server
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor dramatically! Use the rewriting logfile at a
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <em>Level</em> greater than 2 only for debugging!
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</note>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<example><title>Example</title>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzorRewriteLogLevel 3
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</example>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</usage>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</directivesynopsis>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<directivesynopsis>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<name>RewriteLock</name>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<description>Sets the name of the lock file used for <directive
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzormodule="mod_rewrite">RewriteMap</directive>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzorsynchronization</description>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<syntax>RewriteLock <em>file-path</em></syntax>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<contextlist><context>server config</context></contextlist>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<usage>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <p>This directive sets the filename for a synchronization
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor lockfile which mod_rewrite needs to communicate with <directive
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor module="mod_rewrite">RewriteMap</directive>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <em>programs</em>. Set this lockfile to a local path (not on a
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor NFS-mounted device) when you want to use a rewriting
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor map-program. It is not required for other types of rewriting
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor maps.</p>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</usage>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</directivesynopsis>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<directivesynopsis>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<name>RewriteMap</name>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<description>Defines a mapping function for key-lookup</description>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<syntax>RewriteMap <em>MapName</em> <em>MapType</em>:<em>MapSource</em>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</syntax>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<contextlist><context>server config</context><context>virtual host</context>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</contextlist>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<compatibility>The choice of different dbm types is available in
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzorApache 2.0.41 and later</compatibility>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<usage>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <p>The <directive>RewriteMap</directive> directive defines a
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <em>Rewriting Map</em> which can be used inside rule
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor substitution strings by the mapping-functions to
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor insert/substitute fields through a key lookup. The source of
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic this lookup can be of various types.</p>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <p>The <a id="mapfunc" name="mapfunc"><em>MapName</em></a> is
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor the name of the map and will be used to specify a
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf mapping-function for the substitution strings of a rewriting
c867dba1041640ecec7c8194d35a5b4ffce442earbowen rule via one of the following constructs:</p>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <p class="indent">
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <strong><code>${</code> <em>MapName</em> <code>:</code>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic <em>LookupKey</em> <code>}</code><br />
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic <code>${</code> <em>MapName</em> <code>:</code>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic <em>LookupKey</em> <code>|</code> <em>DefaultValue</em>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic <code>}</code></strong>
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf </p>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <p>When such a construct occurs, the map <em>MapName</em> is
c867dba1041640ecec7c8194d35a5b4ffce442earbowen consulted and the key <em>LookupKey</em> is looked-up. If the
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor key is found, the map-function construct is substituted by
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <em>SubstValue</em>. If the key is not found then it is
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor substituted by <em>DefaultValue</em> or by the empty string
c867dba1041640ecec7c8194d35a5b4ffce442earbowen if no <em>DefaultValue</em> was specified.</p>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <p>For example, you might define a
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <directive>RewriteMap</directive> as:</p>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <example>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor RewriteMap examplemap txt:/path/to/file/map.txt
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor </example>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <p>You would then be able to use this map in a
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <directive>RewriteRule</directive> as follows:</p>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <example>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen RewriteRule ^/ex/(.*) ${examplemap:$1}
c867dba1041640ecec7c8194d35a5b4ffce442earbowen </example>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <p>The following combinations for <em>MapType</em> and
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <em>MapSource</em> can be used:</p>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <ul>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <li>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <strong>Standard Plain Text</strong><br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor MapType: <code>txt</code>, MapSource: Unix filesystem
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor path to valid regular file
53cf0034f617fdca55a345580e13afd88000e9ccjim
53cf0034f617fdca55a345580e13afd88000e9ccjim <p>This is the standard rewriting map feature where the
53cf0034f617fdca55a345580e13afd88000e9ccjim <em>MapSource</em> is a plain ASCII file containing
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor either blank lines, comment lines (starting with a '#'
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor character) or pairs like the following - one per
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor line.</p>
2b6565aedca9e9c10691b12fd2f3689bf4c85bc7jim
2b6565aedca9e9c10691b12fd2f3689bf4c85bc7jim <p class="indent">
2b6565aedca9e9c10691b12fd2f3689bf4c85bc7jim <strong><em>MatchingKey</em>
2b6565aedca9e9c10691b12fd2f3689bf4c85bc7jim <em>SubstValue</em></strong>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor </p>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<example><title>Example</title>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<pre>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor##
c867dba1041640ecec7c8194d35a5b4ffce442earbowen## map.txt -- rewriting map
c867dba1041640ecec7c8194d35a5b4ffce442earbowen##
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowenRalf.S.Engelschall rse # Bastard Operator From Hell
aa2ff7f8e8477e2b9d20dc2e72737d6bd5145465sfMr.Joe.Average joe # Mr. Average
aa2ff7f8e8477e2b9d20dc2e72737d6bd5145465sf</pre>
aa2ff7f8e8477e2b9d20dc2e72737d6bd5145465sf</example>
aa2ff7f8e8477e2b9d20dc2e72737d6bd5145465sf
aa2ff7f8e8477e2b9d20dc2e72737d6bd5145465sf<example>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzorRewriteMap real-to-user txt:/path/to/file/map.txt
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</example>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor </li>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <li>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <strong>Randomized Plain Text</strong><br />
c867dba1041640ecec7c8194d35a5b4ffce442earbowen MapType: <code>rnd</code>, MapSource: Unix filesystem
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor path to valid regular file
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic <p>This is identical to the Standard Plain Text variant
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic above but with a special post-processing feature: After
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic looking up a value it is parsed according to contained
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic ``<code>|</code>'' characters which have the meaning of
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic ``or''. In other words they indicate a set of
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor alternatives from which the actual returned value is
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor chosen randomly. For example, you might use the following map
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor file and directives to provide a random load balancing between
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor several back-end server, via a reverse-proxy. Images are sent
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor to one of the servers in the 'static' pool, while everything
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic else is sent to one of the 'dynamic' pool.</p>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic <p>Example:</p>
4b311579b2c8aebac85fb7cb8ac89e6c37b4bc1asf
4b311579b2c8aebac85fb7cb8ac89e6c37b4bc1asf<example><title>Rewrite map file</title>
4b311579b2c8aebac85fb7cb8ac89e6c37b4bc1asf<pre>
4b311579b2c8aebac85fb7cb8ac89e6c37b4bc1asf##
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic## map.txt -- rewriting map
c867dba1041640ecec7c8194d35a5b4ffce442earbowen##
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzorstatic www1|www2|www3|www4
c867dba1041640ecec7c8194d35a5b4ffce442earbowendynamic www5|www6
c867dba1041640ecec7c8194d35a5b4ffce442earbowen</pre>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen</example>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<example><title>Configuration directives</title>
c867dba1041640ecec7c8194d35a5b4ffce442earbowenRewriteMap servers rnd:/path/to/file/map.txt<br />
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzorRewriteRule ^/(.*\.(png|gif|jpg)) http://${servers:static}/$1
c867dba1041640ecec7c8194d35a5b4ffce442earbowen[NC,P,L]<br />
c867dba1041640ecec7c8194d35a5b4ffce442earbowenRewriteRule ^/(.*) http://${servers:dynamic}/$1 [P,L]
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</example>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen </li>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <li>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <strong>Hash File</strong><br /> MapType:
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <code>dbm[=<em>type</em>]</code>, MapSource: Unix filesystem
c867dba1041640ecec7c8194d35a5b4ffce442earbowen path to valid regular file
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <p>Here the source is a binary format DBM file containing
c867dba1041640ecec7c8194d35a5b4ffce442earbowen the same contents as a <em>Plain Text</em> format file, but
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor in a special representation which is optimized for really
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor fast lookups. The <em>type</em> can be sdbm, gdbm, ndbm, or
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor db depending on <a href="/install.html#dbm">compile-time
c867dba1041640ecec7c8194d35a5b4ffce442earbowen settings</a>. If the <em>type</em> is omitted, the
c867dba1041640ecec7c8194d35a5b4ffce442earbowen compile-time default will be chosen. You can create such a
c867dba1041640ecec7c8194d35a5b4ffce442earbowen file with any DBM tool or with the following Perl
c867dba1041640ecec7c8194d35a5b4ffce442earbowen script. Be sure to adjust it to create the appropriate
c867dba1041640ecec7c8194d35a5b4ffce442earbowen type of DBM. The example creates an NDBM file.</p>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<example>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<pre>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen#!/path/to/bin/perl
c867dba1041640ecec7c8194d35a5b4ffce442earbowen##
c867dba1041640ecec7c8194d35a5b4ffce442earbowen## txt2dbm -- convert txt map to dbm format
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor##
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzoruse NDBM_File;
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzoruse Fcntl;
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
c867dba1041640ecec7c8194d35a5b4ffce442earbowen($txtmap, $dbmmap) = @ARGV;
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowenopen(TXT, "&lt;$txtmap") or die "Couldn't open $txtmap!\n";
c867dba1041640ecec7c8194d35a5b4ffce442earbowentie (%DB, 'NDBM_File', $dbmmap,O_RDWR|O_TRUNC|O_CREAT, 0644)
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf or die "Couldn't create $dbmmap!\n";
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowenwhile (&lt;TXT&gt;) {
c867dba1041640ecec7c8194d35a5b4ffce442earbowen next if (/^\s*#/ or /^\s*$/);
c867dba1041640ecec7c8194d35a5b4ffce442earbowen $DB{$1} = $2 if (/^\s*(\S+)\s+(\S+)/);
c867dba1041640ecec7c8194d35a5b4ffce442earbowen}
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowenuntie %DB;
c867dba1041640ecec7c8194d35a5b4ffce442earbowenclose(TXT);
c867dba1041640ecec7c8194d35a5b4ffce442earbowen</pre>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen</example>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<example>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen$ txt2dbm map.txt map.db
c867dba1041640ecec7c8194d35a5b4ffce442earbowen</example>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen </li>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <li>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <strong>Internal Function</strong><br />
c867dba1041640ecec7c8194d35a5b4ffce442earbowen MapType: <code>int</code>, MapSource: Internal Apache
c867dba1041640ecec7c8194d35a5b4ffce442earbowen function
dcf9f04d8ec0fcd7b07320331bf342328b201decrbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <p>Here, the source is an internal Apache function.
c867dba1041640ecec7c8194d35a5b4ffce442earbowen Currently you cannot create your own, but the following
c867dba1041640ecec7c8194d35a5b4ffce442earbowen functions already exist:</p>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <ul>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <li><strong>toupper</strong>:<br />
c867dba1041640ecec7c8194d35a5b4ffce442earbowen Converts the key to all upper case.</li>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <li><strong>tolower</strong>:<br />
c867dba1041640ecec7c8194d35a5b4ffce442earbowen Converts the key to all lower case.</li>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <li><strong>escape</strong>:<br />
c867dba1041640ecec7c8194d35a5b4ffce442earbowen Translates special characters in the key to
c867dba1041640ecec7c8194d35a5b4ffce442earbowen hex-encodings.</li>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <li><strong>unescape</strong>:<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor Translates hex-encodings in the key back to
c867dba1041640ecec7c8194d35a5b4ffce442earbowen special characters.</li>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen </ul>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen </li>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <li>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <strong>External Rewriting Program</strong><br />
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf MapType: <code>prg</code>, MapSource: Unix filesystem
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf path to valid regular file
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <p>Here the source is a program, not a map file. To
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor create it you can use a language of your choice, but
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor the result has to be an executable program (either
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor object-code or a script with the magic cookie trick
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor '<code>#!/path/to/interpreter</code>' as the first
c867dba1041640ecec7c8194d35a5b4ffce442earbowen line).</p>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <p>This program is started once, when the Apache server
c867dba1041640ecec7c8194d35a5b4ffce442earbowen is started, and then communicates with the rewriting engine
c867dba1041640ecec7c8194d35a5b4ffce442earbowen via its <code>stdin</code> and <code>stdout</code>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor file-handles. For each map-function lookup it will
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor receive the key to lookup as a newline-terminated string
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor on <code>stdin</code>. It then has to give back the
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor looked-up value as a newline-terminated string on
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <code>stdout</code> or the four-character string
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor ``<code>NULL</code>'' if it fails (<em>i.e.</em>, there
c867dba1041640ecec7c8194d35a5b4ffce442earbowen is no corresponding value for the given key). A trivial
c867dba1041640ecec7c8194d35a5b4ffce442earbowen program which will implement a 1:1 map (<em>i.e.</em>,
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor key == value) could be:</p>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<example>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<pre>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor#!/usr/bin/perl
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor$| = 1;
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzorwhile (&lt;STDIN&gt;) {
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor # ...put here any transformations or lookups...
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor print $_;
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor}
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</pre>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</example>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <p>But be very careful:</p>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <ol>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <li>``<em>Keep it simple, stupid</em>'' (KISS).
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor If this program hangs, it will cause Apache to hang
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor when trying to use the relevant rewrite rule.</li>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <li>A common mistake is to use buffered I/O on
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <code>stdout</code>. Avoid this, as it will cause a deadloop!
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor ``<code>$|=1</code>'' is used above, to prevent this.</li>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <li>The <directive
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor module="mod_rewrite">RewriteLock</directive> directive can
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor be used to define a lockfile which mod_rewrite can use to synchronize
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor communication with the mapping program. By default no such
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor synchronization takes place.</li>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen </ol>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen </li>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <li>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <p><strong>SQL Query</strong><br />
c867dba1041640ecec7c8194d35a5b4ffce442earbowen MapType: <code>dbd</code> or <code>fastdbd</code>,
c867dba1041640ecec7c8194d35a5b4ffce442earbowen MapSource: An SQL SELECT statement that takes a single
c867dba1041640ecec7c8194d35a5b4ffce442earbowen argument and returns a single value.</p>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <p>This uses <module>mod_dbd</module> to implement a rewritemap
c867dba1041640ecec7c8194d35a5b4ffce442earbowen by lookup in an SQL database. There are two forms:
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <code>fastdbd</code> caches database lookups internally,
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <code>dbd</code> doesn't. So <code>dbd</code> incurs a
c867dba1041640ecec7c8194d35a5b4ffce442earbowen performance penalty but responds immediately if the database
c867dba1041640ecec7c8194d35a5b4ffce442earbowen contents are updated, while <code>fastdbd</code> is more
c867dba1041640ecec7c8194d35a5b4ffce442earbowen efficient but won't re-read database contents until server
c867dba1041640ecec7c8194d35a5b4ffce442earbowen restart.</p>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <p>If a query returns more than one row, a random row from
c867dba1041640ecec7c8194d35a5b4ffce442earbowen the result set is used.</p>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<example>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<title>Example</title>
c867dba1041640ecec7c8194d35a5b4ffce442earbowenRewriteMap myquery "fastdbd:SELECT destination FROM rewrite WHERE source = %s"
c867dba1041640ecec7c8194d35a5b4ffce442earbowen</example>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen </li>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen </ul>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <p>The <directive>RewriteMap</directive> directive can occur more than
c867dba1041640ecec7c8194d35a5b4ffce442earbowen once. For each mapping-function use one
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <directive>RewriteMap</directive> directive to declare its rewriting
c867dba1041640ecec7c8194d35a5b4ffce442earbowen mapfile. While you cannot <strong>declare</strong> a map in
c867dba1041640ecec7c8194d35a5b4ffce442earbowen per-directory context it is of course possible to
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <strong>use</strong> this map in per-directory context. </p>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<note><title>Note</title> For plain text and DBM format files the
c867dba1041640ecec7c8194d35a5b4ffce442earbowenlooked-up keys are cached in-core until the <code>mtime</code> of the
c867dba1041640ecec7c8194d35a5b4ffce442earbowenmapfile changes or the server does a restart. This way you can have
c867dba1041640ecec7c8194d35a5b4ffce442earbowenmap-functions in rules which are used for <strong>every</strong>
c867dba1041640ecec7c8194d35a5b4ffce442earbowenrequest. This is no problem, because the external lookup only happens
c867dba1041640ecec7c8194d35a5b4ffce442earbowenonce!
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf</note>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen</usage>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen</directivesynopsis>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<directivesynopsis>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<name>RewriteBase</name>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<description>Sets the base URL for per-directory rewrites</description>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<syntax>RewriteBase <em>URL-path</em></syntax>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<default>See usage for information.</default>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<contextlist><context>directory</context><context>.htaccess</context>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen</contextlist>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<override>FileInfo</override>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<usage>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <p>The <directive>RewriteBase</directive> directive explicitly
c867dba1041640ecec7c8194d35a5b4ffce442earbowen sets the base URL for per-directory rewrites. As you will see
c867dba1041640ecec7c8194d35a5b4ffce442earbowen below, <directive module="mod_rewrite">RewriteRule</directive>
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf can be used in per-directory config files
c867dba1041640ecec7c8194d35a5b4ffce442earbowen (<code>.htaccess</code>). In such a case, it will act locally,
c867dba1041640ecec7c8194d35a5b4ffce442earbowen stripping the local directory prefix before processing, and applying
c867dba1041640ecec7c8194d35a5b4ffce442earbowen rewrite rules only to the remainder. When processing is complete, the
c867dba1041640ecec7c8194d35a5b4ffce442earbowen prefix is automatically added back to the
c867dba1041640ecec7c8194d35a5b4ffce442earbowen path. The default setting is; <directive>RewriteBase</directive> <em>physical-directory-path</em></p>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <p>When a substitution occurs for a new URL, this module has
c867dba1041640ecec7c8194d35a5b4ffce442earbowen to re-inject the URL into the server processing. To be able
c867dba1041640ecec7c8194d35a5b4ffce442earbowen to do this it needs to know what the corresponding URL-prefix
c867dba1041640ecec7c8194d35a5b4ffce442earbowen or URL-base is. By default this prefix is the corresponding
c867dba1041640ecec7c8194d35a5b4ffce442earbowen filepath itself. <strong>However, for most websites, URLs are NOT
c867dba1041640ecec7c8194d35a5b4ffce442earbowen directly related to physical filename paths, so this
c867dba1041640ecec7c8194d35a5b4ffce442earbowen assumption will often be wrong!</strong> Therefore, you can
c867dba1041640ecec7c8194d35a5b4ffce442earbowen use the <code>RewriteBase</code> directive to specify the
c867dba1041640ecec7c8194d35a5b4ffce442earbowen correct URL-prefix.</p>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<note> If your webserver's URLs are <strong>not</strong> directly
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzorrelated to physical file paths, you will need to use
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<directive>RewriteBase</directive> in every <code>.htaccess</code>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzorfile where you want to use <directive
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzormodule="mod_rewrite">RewriteRule</directive> directives.
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</note>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <p> For example, assume the following per-directory config file:</p>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<example>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<pre>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor#
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor# /abc/def/.htaccess -- per-dir config file for directory /abc/def
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor# Remember: /abc/def is the physical path of /xyz, <em>i.e.</em>, the server
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor# has a 'Alias /xyz /abc/def' directive <em>e.g.</em>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor#
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzorRewriteEngine On
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor# let the server know that we were reached via /xyz and not
c867dba1041640ecec7c8194d35a5b4ffce442earbowen# via the physical path prefix /abc/def
c867dba1041640ecec7c8194d35a5b4ffce442earbowenRewriteBase /xyz
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen# now the rewriting rules
c867dba1041640ecec7c8194d35a5b4ffce442earbowenRewriteRule ^oldstuff\.html$ newstuff.html
c867dba1041640ecec7c8194d35a5b4ffce442earbowen</pre>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen</example>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <p>In the above example, a request to
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <code>/xyz/oldstuff.html</code> gets correctly rewritten to
c867dba1041640ecec7c8194d35a5b4ffce442earbowen the physical file <code>/abc/def/newstuff.html</code>.</p>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<note><title>For Apache Hackers</title>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<p>The following list gives detailed information about
c867dba1041640ecec7c8194d35a5b4ffce442earbowen the internal processing steps:</p>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<pre>
c867dba1041640ecec7c8194d35a5b4ffce442earbowenRequest:
c867dba1041640ecec7c8194d35a5b4ffce442earbowen /xyz/oldstuff.html
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowenInternal Processing:
c867dba1041640ecec7c8194d35a5b4ffce442earbowen /xyz/oldstuff.html -&gt; /abc/def/oldstuff.html (per-server Alias)
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor /abc/def/oldstuff.html -&gt; /abc/def/newstuff.html (per-dir RewriteRule)
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor /abc/def/newstuff.html -&gt; /xyz/newstuff.html (per-dir RewriteBase)
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor /xyz/newstuff.html -&gt; /abc/def/newstuff.html (per-server Alias)
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzorResult:
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor /abc/def/newstuff.html
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</pre>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <p>This seems very complicated, but is in fact
c867dba1041640ecec7c8194d35a5b4ffce442earbowen correct Apache internal processing. Because the
c867dba1041640ecec7c8194d35a5b4ffce442earbowen per-directory rewriting comes late in the
c867dba1041640ecec7c8194d35a5b4ffce442earbowen process, the rewritten request
c867dba1041640ecec7c8194d35a5b4ffce442earbowen has to be re-injected into the Apache kernel.
c867dba1041640ecec7c8194d35a5b4ffce442earbowen This is not the serious overhead it may seem to be -
c867dba1041640ecec7c8194d35a5b4ffce442earbowen this re-injection is completely internal to the
c867dba1041640ecec7c8194d35a5b4ffce442earbowen Apache server (and the same procedure is used by
c867dba1041640ecec7c8194d35a5b4ffce442earbowen many other operations within Apache).</p>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</note>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</usage>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</directivesynopsis>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<directivesynopsis>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic<name>RewriteCond</name>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic<description>Defines a condition under which rewriting will take place
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic</description>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic<syntax> RewriteCond
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic <em>TestString</em> <em>CondPattern</em></syntax>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic<contextlist><context>server config</context><context>virtual host</context>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic<context>directory</context><context>.htaccess</context></contextlist>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic<override>FileInfo</override>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic<usage>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic <p>The <directive>RewriteCond</directive> directive defines a
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic rule condition. One or more <directive>RewriteCond</directive>
fe2be2903c65e2f99f04199655ea5f97a75825d0humbedooh can precede a <directive module="mod_rewrite">RewriteRule</directive>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic directive. The following rule is then only used if both
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic the current state of the URI matches its pattern, <strong
fe2be2903c65e2f99f04199655ea5f97a75825d0humbedooh >and</strong> if these conditions are met.</p>
fe2be2903c65e2f99f04199655ea5f97a75825d0humbedooh
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic <p><em>TestString</em> is a string which can contain the
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic following expanded constructs in addition to plain text:</p>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <ul>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <li>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <strong>RewriteRule backreferences</strong>: These are
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor backreferences of the form <strong><code>$N</code></strong>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor (0 &lt;= N &lt;= 9), which provide access to the grouped
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor parts (in parentheses) of the pattern, from the
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <code>RewriteRule</code> which is subject to the current
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor set of <code>RewriteCond</code> conditions..
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor </li>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <li>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <strong>RewriteCond backreferences</strong>: These are
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor backreferences of the form <strong><code>%N</code></strong>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor (1 &lt;= N &lt;= 9), which provide access to the grouped
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor parts (again, in parentheses) of the pattern, from the last matched
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <code>RewriteCond</code> in the current set
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor of conditions.
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor </li>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <li>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <strong>RewriteMap expansions</strong>: These are
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor expansions of the form <strong><code
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor >${mapname:key|default}</code></strong>.
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor See <a href="#mapfunc">the documentation for
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor RewriteMap</a> for more details.
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor </li>
fe2be2903c65e2f99f04199655ea5f97a75825d0humbedooh <li>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <strong>Server-Variables</strong>: These are variables of
c867dba1041640ecec7c8194d35a5b4ffce442earbowen the form
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <strong><code>%{</code> <em>NAME_OF_VARIABLE</em>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <code>}</code></strong>
fe2be2903c65e2f99f04199655ea5f97a75825d0humbedooh where <em>NAME_OF_VARIABLE</em> can be a string taken
fe2be2903c65e2f99f04199655ea5f97a75825d0humbedooh from the following list:
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <table>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <columnspec><column width=".3"/><column width=".3"/>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <column width=".3"/></columnspec>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <tr>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <th>HTTP headers:</th> <th>connection &amp; request:</th> <th></th>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor </tr>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <tr>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <td>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor HTTP_USER_AGENT<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor HTTP_REFERER<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor HTTP_COOKIE<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor HTTP_FORWARDED<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor HTTP_HOST<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor HTTP_PROXY_CONNECTION<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor HTTP_ACCEPT<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor </td>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <td>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor REMOTE_ADDR<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor REMOTE_HOST<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor REMOTE_PORT<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor REMOTE_USER<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor REMOTE_IDENT<br />
fe2be2903c65e2f99f04199655ea5f97a75825d0humbedooh REQUEST_METHOD<br />
c867dba1041640ecec7c8194d35a5b4ffce442earbowen SCRIPT_FILENAME<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor PATH_INFO<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor QUERY_STRING<br />
c867dba1041640ecec7c8194d35a5b4ffce442earbowen AUTH_TYPE<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor </td>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <td></td>
fe2be2903c65e2f99f04199655ea5f97a75825d0humbedooh </tr>
fe2be2903c65e2f99f04199655ea5f97a75825d0humbedooh
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <tr>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <th>server internals:</th> <th>date and time:</th> <th>specials:</th>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor </tr>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <tr>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <td>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor DOCUMENT_ROOT<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor SERVER_ADMIN<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor SERVER_NAME<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor SERVER_ADDR<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor SERVER_PORT<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor SERVER_PROTOCOL<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor SERVER_SOFTWARE<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor </td>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <td>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor TIME_YEAR<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor TIME_MON<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor TIME_DAY<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor TIME_HOUR<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor TIME_MIN<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor TIME_SEC<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor TIME_WDAY<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor TIME<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor </td>
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <td>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor API_VERSION<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor THE_REQUEST<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor REQUEST_URI<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor REQUEST_FILENAME<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor IS_SUBREQ<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor HTTPS<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor </td>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor </tr>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor </table>
aa2ff7f8e8477e2b9d20dc2e72737d6bd5145465sf
aa2ff7f8e8477e2b9d20dc2e72737d6bd5145465sf <p>These variables all
aa2ff7f8e8477e2b9d20dc2e72737d6bd5145465sf correspond to the similarly named HTTP
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor MIME-headers, C variables of the Apache server or
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <code>struct tm</code> fields of the Unix system.
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor Most are documented elsewhere in the Manual or in
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor the CGI specification. Those that are special to
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor mod_rewrite include those below.</p>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <note>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <dl>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <dt><code>IS_SUBREQ</code></dt>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <dd>Will contain the text "true" if the request
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor currently being processed is a sub-request,
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor "false" otherwise. Sub-requests may be generated
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor by modules that need to resolve additional files
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor or URIs in order to complete their tasks.</dd>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <dt><code>API_VERSION</code></dt>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <dd>This is the version of the Apache module API
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor (the internal interface between server and
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor module) in the current httpd build, as defined in
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor include/ap_mmn.h. The module API version
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor corresponds to the version of Apache in use (in
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor the release version of Apache 1.3.14, for
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor instance, it is 19990320:10), but is mainly of
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor interest to module authors.</dd>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <dt><code>THE_REQUEST</code></dt>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <dd>The full HTTP request line sent by the
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor browser to the server (e.g., "<code>GET
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor /index.html HTTP/1.1</code>"). This does not
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor include any additional headers sent by the
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor browser.</dd>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <dt><code>REQUEST_URI</code></dt>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <dd>The resource requested in the HTTP request
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor line. (In the example above, this would be
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor "/index.html".)</dd>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <dt><code>REQUEST_FILENAME</code></dt>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <dd>The full local filesystem path to the file or
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor script matching the request.</dd>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <dt><code>HTTPS</code></dt>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <dd>Will contain the text "on" if the connection is
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor using SSL/TLS, or "off" otherwise. (This variable
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor can be safely used regardless of whether or not
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <module>mod_ssl</module> is loaded).</dd>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor </dl>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</note>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor </li>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor </ul>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <p>Other things you should be aware of:</p>
70f5253b24dd333c67fb6502d557a8b48ad3ba87igalic
70f5253b24dd333c67fb6502d557a8b48ad3ba87igalic <ol>
70f5253b24dd333c67fb6502d557a8b48ad3ba87igalic <li>The variables SCRIPT_FILENAME and REQUEST_FILENAME
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor contain the same value - the value of the
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <code>filename</code> field of the internal
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <code>request_rec</code> structure of the Apache server.
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor The first name is the commonly known CGI variable name
fe2be2903c65e2f99f04199655ea5f97a75825d0humbedooh while the second is the appropriate counterpart of
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor REQUEST_URI (which contains the value of the
fe2be2903c65e2f99f04199655ea5f97a75825d0humbedooh <code>uri</code> field of <code>request_rec</code>).</li>
fe2be2903c65e2f99f04199655ea5f97a75825d0humbedooh
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <li>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <code>%{ENV:variable}</code>, where <em>variable</em> can be
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor any environment variable, is also available.
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor This is looked-up via internal
fe2be2903c65e2f99f04199655ea5f97a75825d0humbedooh Apache structures and (if not found there) via
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <code>getenv()</code> from the Apache server process.</li>
fe2be2903c65e2f99f04199655ea5f97a75825d0humbedooh
fe2be2903c65e2f99f04199655ea5f97a75825d0humbedooh <li>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <code>%{SSL:variable}</code>, where <em>variable</em> is the
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor name of an <a href="mod_ssl.html#envvars">SSL environment
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor variable</a>, can be used whether or not
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <module>mod_ssl</module> is loaded, but will always expand to
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor the empty string if it is not. Example:
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <code>%{SSL:SSL_CIPHER_USEKEYSIZE}</code> may expand to
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <code>128</code>.</li>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <li>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <code>%{HTTP:header}</code>, where <em>header</em> can be
c867dba1041640ecec7c8194d35a5b4ffce442earbowen any HTTP MIME-header name, can always be used to obtain the
c867dba1041640ecec7c8194d35a5b4ffce442earbowen value of a header sent in the HTTP request.
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor Example: <code>%{HTTP:Proxy-Connection}</code> is
c867dba1041640ecec7c8194d35a5b4ffce442earbowen the value of the HTTP header
c867dba1041640ecec7c8194d35a5b4ffce442earbowen ``<code>Proxy-Connection:</code>''.</li>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <li>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <code>%{LA-U:variable}</code> can be used for look-aheads which perform
c867dba1041640ecec7c8194d35a5b4ffce442earbowen an internal (URL-based) sub-request to determine the final
c867dba1041640ecec7c8194d35a5b4ffce442earbowen value of <em>variable</em>. This can be used to access
c867dba1041640ecec7c8194d35a5b4ffce442earbowen variable for rewriting which is not available at the current
c867dba1041640ecec7c8194d35a5b4ffce442earbowen stage, but will be set in a later phase.
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <p>For instance, to rewrite according to the
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <code>REMOTE_USER</code> variable from within the
c867dba1041640ecec7c8194d35a5b4ffce442earbowen per-server context (<code>httpd.conf</code> file) you must
c867dba1041640ecec7c8194d35a5b4ffce442earbowen use <code>%{LA-U:REMOTE_USER}</code> - this
c867dba1041640ecec7c8194d35a5b4ffce442earbowen variable is set by the authorization phases, which come
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <em>after</em> the URL translation phase (during which mod_rewrite
c867dba1041640ecec7c8194d35a5b4ffce442earbowen operates).</p>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <p>On the other hand, because mod_rewrite implements
c867dba1041640ecec7c8194d35a5b4ffce442earbowen its per-directory context (<code>.htaccess</code> file) via
c867dba1041640ecec7c8194d35a5b4ffce442earbowen the Fixup phase of the API and because the authorization
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf phases come <em>before</em> this phase, you just can use
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <code>%{REMOTE_USER}</code> in that context.</p></li>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <li>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <code>%{LA-F:variable}</code> can be used to perform an internal
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor (filename-based) sub-request, to determine the final value
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor of <em>variable</em>. Most of the time, this is the same as
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor LA-U above.</li>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor </ol>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <p><em>CondPattern</em> is the condition pattern,
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor a regular expression which is applied to the
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor current instance of the <em>TestString</em>.
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen <em>TestString</em> is first evaluated, before being matched against
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <em>CondPattern</em>.</p>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <p><strong>Remember:</strong> <em>CondPattern</em> is a
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <em>perl compatible regular expression</em> with some
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor additions:</p>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <ol>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <li>You can prefix the pattern string with a
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor '<code>!</code>' character (exclamation mark) to specify a
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <strong>non</strong>-matching pattern.</li>
3739b903eb6f5b0944056b2e98d5d8877d003c6figalic
70f5253b24dd333c67fb6502d557a8b48ad3ba87igalic <li>
70f5253b24dd333c67fb6502d557a8b48ad3ba87igalic There are some special variants of <em>CondPatterns</em>.
70f5253b24dd333c67fb6502d557a8b48ad3ba87igalic Instead of real regular expression strings you can also
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor use one of the following:
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <ul>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <li>'<strong>&lt;CondPattern</strong>' (lexicographically
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor precedes)<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor Treats the <em>CondPattern</em> as a plain string and
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor compares it lexicographically to <em>TestString</em>. True if
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <em>TestString</em> lexicographically precedes
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <em>CondPattern</em>.</li>
3739b903eb6f5b0944056b2e98d5d8877d003c6figalic
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <li>'<strong>&gt;CondPattern</strong>' (lexicographically
70f5253b24dd333c67fb6502d557a8b48ad3ba87igalic follows)<br />
70f5253b24dd333c67fb6502d557a8b48ad3ba87igalic Treats the <em>CondPattern</em> as a plain string and
70f5253b24dd333c67fb6502d557a8b48ad3ba87igalic compares it lexicographically to <em>TestString</em>. True if
70f5253b24dd333c67fb6502d557a8b48ad3ba87igalic <em>TestString</em> lexicographically follows
70f5253b24dd333c67fb6502d557a8b48ad3ba87igalic <em>CondPattern</em>.</li>
70f5253b24dd333c67fb6502d557a8b48ad3ba87igalic
70f5253b24dd333c67fb6502d557a8b48ad3ba87igalic <li>'<strong>=CondPattern</strong>' (lexicographically
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor equal)<br />
3739b903eb6f5b0944056b2e98d5d8877d003c6figalic Treats the <em>CondPattern</em> as a plain string and
3739b903eb6f5b0944056b2e98d5d8877d003c6figalic compares it lexicographically to <em>TestString</em>. True if
3739b903eb6f5b0944056b2e98d5d8877d003c6figalic <em>TestString</em> is lexicographically equal to
3739b903eb6f5b0944056b2e98d5d8877d003c6figalic <em>CondPattern</em> (the two strings are exactly
3739b903eb6f5b0944056b2e98d5d8877d003c6figalic equal, character for character). If <em>CondPattern</em>
3739b903eb6f5b0944056b2e98d5d8877d003c6figalic is <code>""</code> (two quotation marks) this
3739b903eb6f5b0944056b2e98d5d8877d003c6figalic compares <em>TestString</em> to the empty string.</li>
3739b903eb6f5b0944056b2e98d5d8877d003c6figalic
3739b903eb6f5b0944056b2e98d5d8877d003c6figalic <li>'<strong>-d</strong>' (is
3739b903eb6f5b0944056b2e98d5d8877d003c6figalic <strong>d</strong>irectory)<br />
9652bc3a93433d52f80579062986ead2afe0d11fsf Treats the <em>TestString</em> as a pathname and tests
9652bc3a93433d52f80579062986ead2afe0d11fsf whether or not it exists, and is a directory.</li>
9652bc3a93433d52f80579062986ead2afe0d11fsf
9652bc3a93433d52f80579062986ead2afe0d11fsf <li>'<strong>-f</strong>' (is regular
9652bc3a93433d52f80579062986ead2afe0d11fsf <strong>f</strong>ile)<br />
9652bc3a93433d52f80579062986ead2afe0d11fsf Treats the <em>TestString</em> as a pathname and tests
9652bc3a93433d52f80579062986ead2afe0d11fsf whether or not it exists, and is a regular file.</li>
9652bc3a93433d52f80579062986ead2afe0d11fsf
9652bc3a93433d52f80579062986ead2afe0d11fsf <li>'<strong>-s</strong>' (is regular file, with
9652bc3a93433d52f80579062986ead2afe0d11fsf <strong>s</strong>ize)<br />
9652bc3a93433d52f80579062986ead2afe0d11fsf Treats the <em>TestString</em> as a pathname and tests
9652bc3a93433d52f80579062986ead2afe0d11fsf whether or not it exists, and is a regular file with size greater
9652bc3a93433d52f80579062986ead2afe0d11fsf than zero.</li>
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen <li>'<strong>-l</strong>' (is symbolic
9652bc3a93433d52f80579062986ead2afe0d11fsf <strong>l</strong>ink)<br />
80d24ae8901685c116c757ea384f981f8041e4cehumbedooh Treats the <em>TestString</em> as a pathname and tests
80d24ae8901685c116c757ea384f981f8041e4cehumbedooh whether or not it exists, and is a symbolic link.</li>
80d24ae8901685c116c757ea384f981f8041e4cehumbedooh
80d24ae8901685c116c757ea384f981f8041e4cehumbedooh <li>'<strong>-x</strong>' (has e<strong>x</strong>ecutable
80d24ae8901685c116c757ea384f981f8041e4cehumbedooh permissions)<br />
80d24ae8901685c116c757ea384f981f8041e4cehumbedooh Treats the <em>TestString</em> as a pathname and tests
80d24ae8901685c116c757ea384f981f8041e4cehumbedooh whether or not it exists, and has executable permissions.
80d24ae8901685c116c757ea384f981f8041e4cehumbedooh These permissions are determined according to
80d24ae8901685c116c757ea384f981f8041e4cehumbedooh the underlying OS.</li>
80d24ae8901685c116c757ea384f981f8041e4cehumbedooh
80d24ae8901685c116c757ea384f981f8041e4cehumbedooh <li>'<strong>-F</strong>' (is existing file, via
80d24ae8901685c116c757ea384f981f8041e4cehumbedooh subrequest)<br />
80d24ae8901685c116c757ea384f981f8041e4cehumbedooh Checks whether or not <em>TestString</em> is a valid file,
80d24ae8901685c116c757ea384f981f8041e4cehumbedooh accessible via all the server's currently-configured
80d24ae8901685c116c757ea384f981f8041e4cehumbedooh access controls for that path. This uses an internal
80d24ae8901685c116c757ea384f981f8041e4cehumbedooh subrequest to do the check, so use it with care -
80d24ae8901685c116c757ea384f981f8041e4cehumbedooh it can impact your server's performance!</li>
80d24ae8901685c116c757ea384f981f8041e4cehumbedooh
80d24ae8901685c116c757ea384f981f8041e4cehumbedooh <li>'<strong>-U</strong>' (is existing URL, via
80d24ae8901685c116c757ea384f981f8041e4cehumbedooh subrequest)<br />
80d24ae8901685c116c757ea384f981f8041e4cehumbedooh Checks whether or not <em>TestString</em> is a valid URL,
80d24ae8901685c116c757ea384f981f8041e4cehumbedooh accessible via all the server's currently-configured
80d24ae8901685c116c757ea384f981f8041e4cehumbedooh access controls for that path. This uses an internal
80d24ae8901685c116c757ea384f981f8041e4cehumbedooh subrequest to do the check, so use it with care -
80d24ae8901685c116c757ea384f981f8041e4cehumbedooh it can impact your server's performance!</li>
80d24ae8901685c116c757ea384f981f8041e4cehumbedooh </ul>
80d24ae8901685c116c757ea384f981f8041e4cehumbedooh
80d24ae8901685c116c757ea384f981f8041e4cehumbedooh<note><title>Note:</title>
80d24ae8901685c116c757ea384f981f8041e4cehumbedooh All of these tests can
80d24ae8901685c116c757ea384f981f8041e4cehumbedooh also be prefixed by an exclamation mark ('!') to
c417c34be03acec7a46cbc2ea63c659870090081igalic negate their meaning.
c417c34be03acec7a46cbc2ea63c659870090081igalic</note>
c417c34be03acec7a46cbc2ea63c659870090081igalic </li>
c417c34be03acec7a46cbc2ea63c659870090081igalic
c417c34be03acec7a46cbc2ea63c659870090081igalic <li>You can also set special flags for
c417c34be03acec7a46cbc2ea63c659870090081igalic <em>CondPattern</em> by appending
c417c34be03acec7a46cbc2ea63c659870090081igalic <strong><code>[</code><em>flags</em><code>]</code></strong>
c417c34be03acec7a46cbc2ea63c659870090081igalic as the third argument to the <code>RewriteCond</code>
c417c34be03acec7a46cbc2ea63c659870090081igalic directive, where <em>flags</em> is a comma-separated list of any of the
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor following flags:
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <ul>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <li>'<strong><code>nocase|NC</code></strong>'
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor (<strong>n</strong>o <strong>c</strong>ase)<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor This makes the test case-insensitive - differences
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor between 'A-Z' and 'a-z' are ignored, both in the
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor expanded <em>TestString</em> and the <em>CondPattern</em>.
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor This flag is effective only for comparisons between
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <em>TestString</em> and <em>CondPattern</em>. It has no
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen effect on filesystem and subrequest checks.</li>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <li>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor '<strong><code>ornext|OR</code></strong>'
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor (<strong>or</strong> next condition)<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor Use this to combine rule conditions with a local OR
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor instead of the implicit AND. Typical example:
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<example>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<pre>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzorRewriteCond %{REMOTE_HOST} ^host1.* [OR]
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzorRewriteCond %{REMOTE_HOST} ^host2.* [OR]
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzorRewriteCond %{REMOTE_HOST} ^host3.*
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzorRewriteRule ...some special stuff for any of these hosts...
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</pre>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic</example>
35ac4e1a6ec5aa3cfa1a34d8f20fe8a841cc46b7rbowen
35ac4e1a6ec5aa3cfa1a34d8f20fe8a841cc46b7rbowen Without this flag you would have to write the condition/rule
35ac4e1a6ec5aa3cfa1a34d8f20fe8a841cc46b7rbowen pair three times.
35ac4e1a6ec5aa3cfa1a34d8f20fe8a841cc46b7rbowen </li>
35ac4e1a6ec5aa3cfa1a34d8f20fe8a841cc46b7rbowen </ul>
35ac4e1a6ec5aa3cfa1a34d8f20fe8a841cc46b7rbowen </li>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor </ol>
4126704c4950bfd46d32ad54e3b106ac6d868a73sf
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf <p><strong>Example:</strong></p>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic <p>To rewrite the Homepage of a site according to the
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic ``<code>User-Agent:</code>'' header of the request, you can
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic use the following: </p>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic<example>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic<pre>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalicRewriteCond %{HTTP_USER_AGENT} ^Mozilla.*
35ac4e1a6ec5aa3cfa1a34d8f20fe8a841cc46b7rbowenRewriteRule ^/$ /homepage.max.html [L]
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalicRewriteCond %{HTTP_USER_AGENT} ^Lynx.*
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsfRewriteRule ^/$ /homepage.min.html [L]
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzorRewriteRule ^/$ /homepage.std.html [L]
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</pre>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen</example>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic <p>Explanation: If you use a browser which identifies itself
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic as 'Mozilla' (including Netscape Navigator, Mozilla etc), then you
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic get the max homepage (which could include frames, or other special
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic features).
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic If you use the Lynx browser (which is terminal-based), then
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic you get the min homepage (which could be a version designed for
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic easy, text-only browsing).
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic If neither of these conditions apply (you use any other browser,
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic or your browser identifies itself as something non-standard), you get
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic the std (standard) homepage.</p>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic</usage>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic</directivesynopsis>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic<directivesynopsis>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic<name>RewriteRule</name>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic<description>Defines rules for the rewriting engine</description>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic<syntax>RewriteRule
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic <em>Pattern</em> <em>Substitution</em> [<em>flags</em>]</syntax>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic<contextlist><context>server config</context><context>virtual host</context>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic<context>directory</context><context>.htaccess</context></contextlist>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic<override>FileInfo</override>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic<usage>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic <p>The <directive>RewriteRule</directive> directive is the real
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic rewriting workhorse. The directive can occur more than once,
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic with each instance defining a single rewrite rule. The
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic order in which these rules are defined is important - this is the order
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic in which they will be applied at run-time.</p>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic <p><a id="patterns" name="patterns"><em>Pattern</em></a> is
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic a perl compatible <a id="regexp" name="regexp">regular
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic expression</a>. On the first RewriteRule it is applied to the
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic <a href="/directive-dict.html#Syntax">URL-path</a> of the request;
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic subsequent patterns are applied to the output of the last matched
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic RewriteRule.</p>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic<note><title>What is matched?</title>
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic <p>The <em>Pattern</em> will initially be matched against the part of the
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic URL after the hostname and port, and before the query string. If you wish
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic to match against the hostname, port, or query string, use a
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic <directive module="mod_rewrite">RewriteCond</directive> with the
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic <code>%{HTTP_HOST}</code>, <code>%{SERVER_PORT}</code>, or
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <code>%{QUERY_STRING}</code> variables respectively.</p>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</note>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
1093a264c81aa1041581ab059905fb8f7cdfc5e2rbowen
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <p>Some hints on the syntax of <glossary ref="regex">regular
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor expressions</glossary>:</p>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<note><pre>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<strong>Text:</strong>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <strong><code>.</code></strong> Any single character
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <strong><code>[</code></strong>chars<strong><code>]</code></strong> Character class: Any character of the class ``chars''
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <strong><code>[^</code></strong>chars<strong><code>]</code></strong> Character class: Not a character of the class ``chars''
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor text1<strong><code>|</code></strong>text2 Alternative: text1 or text2
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<strong>Quantifiers:</strong>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <strong><code>?</code></strong> 0 or 1 occurrences of the preceding text
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <strong><code>*</code></strong> 0 or N occurrences of the preceding text (N &gt; 0)
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <strong><code>+</code></strong> 1 or N occurrences of the preceding text (N &gt; 1)
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<strong>Grouping:</strong>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <strong><code>(</code></strong>text<strong><code>)</code></strong> Grouping of text
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor (used either to set the borders of an alternative as above, or
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor to make backreferences, where the <strong>N</strong>th group can
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor be referred to on the RHS of a RewriteRule as <code>$</code><strong>N</strong>)
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<strong>Anchors:</strong>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <strong><code>^</code></strong> Start-of-line anchor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <strong><code>$</code></strong> End-of-line anchor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<strong>Escaping:</strong>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <strong><code>\</code></strong>char escape the given char
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor (for instance, to specify the chars "<code>.[]()</code>" <em>etc.</em>)
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</pre></note>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <p>For more information about regular expressions, have a look at the
cae0359c9286c8e34cbccd15eee2da90562c1ee2sf perl regular expression manpage ("<a
cae0359c9286c8e34cbccd15eee2da90562c1ee2sf href="http://www.perldoc.com/perlre.html">perldoc
cae0359c9286c8e34cbccd15eee2da90562c1ee2sf perlre</a>"). If you are interested in more detailed
cae0359c9286c8e34cbccd15eee2da90562c1ee2sf information about regular expressions and their variants
cae0359c9286c8e34cbccd15eee2da90562c1ee2sf (POSIX regex etc.) the following book is dedicated to this topic:</p>
cae0359c9286c8e34cbccd15eee2da90562c1ee2sf
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <p class="indent">
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <em>Mastering Regular Expressions, 2nd Edition</em><br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor Jeffrey E.F. Friedl<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor O'Reilly &amp; Associates, Inc. 2002<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor ISBN 0-596-00289-0<br />
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor </p>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <p>In mod_rewrite, the NOT character
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor ('<code>!</code>') is also available as a possible pattern
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor prefix. This enables you to negate a pattern; to say, for instance:
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor ``<em>if the current URL does <strong>NOT</strong> match this
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor pattern</em>''. This can be used for exceptional cases, where
c7d7b17e921d92419473ebe85ed7e4512001f68fhumbedooh it is easier to match the negative pattern, or as a last
c7d7b17e921d92419473ebe85ed7e4512001f68fhumbedooh default rule.</p>
c7d7b17e921d92419473ebe85ed7e4512001f68fhumbedooh
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<note><title>Note</title>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzorWhen using the NOT character to negate a pattern, you cannot include
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzorgrouped wildcard parts in that pattern. This is because, when the
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzorpattern does NOT match (ie, the negation matches), there are no
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzorcontents for the groups. Thus, if negated patterns are used, you
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzorcannot use <code>$N</code> in the substitution string!
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</note>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <p>The <a id="rhs" name="rhs"><em>Substitution</em></a> of a
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor rewrite rule is the string that replaces the original URL-path that
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor was matched by <em>Pattern</em>. The <em>Substitution</em> may
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor be a:</p>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <dl>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <dt>file-system path</dt>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <dd>Designates the location on the file-system of the resource
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor to be delivered to the client.</dd>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <dt>URL-path</dt>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <dd>A <directive
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor module="core">DocumentRoot</directive>-relative path to the
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor resource to be served. Note that <module>mod_rewrite</module>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor tries to guess whether you have specified a file-system path
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor or a URL-path by checking to see if the first segement of the
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor path exists at the root of the file-system. For example, if
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor you specify a <em>Substitution</em> string of
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <code>/www/file.html</code>, then this will be treated as a
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor URL-path <em>unless</em> a directory named <code>www</code>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor exists at the root or your file-system, in which case it will
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor be treated as a file-system path. If you wish other
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor URL-mapping directives (such as <directive
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor module="mod_alias">Alias</directive>) to be applied to the
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor resulting URL-path, use the <code>[PT]</code> flag as
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor described below.</dd>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <dt>Absolute URL</dt>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <dd>If an absolute URL is specified,
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <module>mod_rewrite</module> checks to see whether the
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor hostname matches the current host. If it does, the scheme and
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor hostname are stripped out and the resulting path is treated as
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor a URL-path. Otherwise, an external redirect is performed for
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor the given URL. To force an external redirect back to the
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor current host, see the <code>[R]</code> flag below.</dd>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <dt><code>-</code> (dash)</dt>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <dd>A dash indicates that no substitution should be performed
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor (the existing path is passed through untouched). This is used
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor when a flag (see below) needs to be applied without changing
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor the path.</dd>
4126704c4950bfd46d32ad54e3b106ac6d868a73sf
4126704c4950bfd46d32ad54e3b106ac6d868a73sf </dl>
35ac4e1a6ec5aa3cfa1a34d8f20fe8a841cc46b7rbowen
4126704c4950bfd46d32ad54e3b106ac6d868a73sf <p>In addition to plain text, the <em>Substition</em> string can include</p>
4126704c4950bfd46d32ad54e3b106ac6d868a73sf
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <ol>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <li>back-references (<code>$N</code>) to the RewriteRule
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor pattern</li>
4126704c4950bfd46d32ad54e3b106ac6d868a73sf
4126704c4950bfd46d32ad54e3b106ac6d868a73sf <li>back-references (<code>%N</code>) to the last matched
4126704c4950bfd46d32ad54e3b106ac6d868a73sf RewriteCond pattern</li>
4126704c4950bfd46d32ad54e3b106ac6d868a73sf
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <li>server-variables as in rule condition test-strings
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor (<code>%{VARNAME}</code>)</li>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <li><a href="#mapfunc">mapping-function</a> calls
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor (<code>${mapname:key|default}</code>)</li>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor </ol>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <p>Back-references are identifiers of the form
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <code>$</code><strong>N</strong>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor (<strong>N</strong>=0..9), which will be replaced
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor by the contents of the <strong>N</strong>th group of the
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor matched <em>Pattern</em>. The server-variables are the same
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor as for the <em>TestString</em> of a <code>RewriteCond</code>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor directive. The mapping-functions come from the
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <code>RewriteMap</code> directive and are explained there.
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor These three types of variables are expanded in the order above.</p>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <p>As already mentioned, all rewrite rules are
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor applied to the <em>Substitution</em> (in the order in which
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor they are defined
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor in the config file). The URL is <strong>completely
c867dba1041640ecec7c8194d35a5b4ffce442earbowen replaced</strong> by the <em>Substitution</em> and the
c867dba1041640ecec7c8194d35a5b4ffce442earbowen rewriting process continues until all rules have been applied,
c867dba1041640ecec7c8194d35a5b4ffce442earbowen or it is explicitly terminated by a
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <code><strong>L</strong></code> flag.</p>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <note><title>Modifying the Query String</title>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <p>By default, the query string is passed through unchanged. You
c867dba1041640ecec7c8194d35a5b4ffce442earbowen can, however, create URLs in the substitution string containing
c867dba1041640ecec7c8194d35a5b4ffce442earbowen a query string part. Simply use a question mark inside the
c867dba1041640ecec7c8194d35a5b4ffce442earbowen substitution string to indicate that the following text should
c867dba1041640ecec7c8194d35a5b4ffce442earbowen be re-injected into the query string. When you want to erase an
c867dba1041640ecec7c8194d35a5b4ffce442earbowen existing query string, end the substitution string with just a
c867dba1041640ecec7c8194d35a5b4ffce442earbowen question mark. To combine new and old query strings, use the
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <code>[QSA]</code> flag.</p>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen </note>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <p>Additionally you can set special <a name="rewriteflags"
c867dba1041640ecec7c8194d35a5b4ffce442earbowen id="rewriteflags">actions</a> to be performed by
c867dba1041640ecec7c8194d35a5b4ffce442earbowen appending <strong><code>[</code><em>flags</em><code>]</code></strong>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen as the third argument to the <code>RewriteRule</code>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen directive. <em>Flags</em> is a comma-separated list, surround by square
c867dba1041640ecec7c8194d35a5b4ffce442earbowen brackets, of any of the following flags: </p>
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <dl>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <dt>'<code>chain|C</code>'
c867dba1041640ecec7c8194d35a5b4ffce442earbowen (chained with next rule)</dt><dd>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen This flag chains the current rule with the next rule
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic (which itself can be chained with the following rule,
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf and so on). This has the following effect: if a rule
c867dba1041640ecec7c8194d35a5b4ffce442earbowen matches, then processing continues as usual -
c867dba1041640ecec7c8194d35a5b4ffce442earbowen the flag has no effect. If the rule does
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <strong>not</strong> match, then all following chained
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic rules are skipped. For instance, it can be used to remove the
c867dba1041640ecec7c8194d35a5b4ffce442earbowen ``<code>.www</code>'' part, inside a per-directory rule set,
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic when you let an external redirect happen (where the
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic ``<code>.www</code>'' part should not occur!).</dd>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <dt>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen '<code>cookie|CO=</code><em>NAME</em>:<em>VAL</em>:<em>domain</em>[:<em>lifetime</em>[:<em>path</em>]]'
c867dba1041640ecec7c8194d35a5b4ffce442earbowen (set cookie)</dt><dd>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen This sets a cookie in the client's browser. The cookie's name
c867dba1041640ecec7c8194d35a5b4ffce442earbowen is specified by <em>NAME</em> and the value is
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <em>VAL</em>. The <em>domain</em> field is the domain of the
c867dba1041640ecec7c8194d35a5b4ffce442earbowen cookie, such as '.apache.org', the optional <em>lifetime</em>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen is the lifetime of the cookie in minutes, and the optional
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <em>path</em> is the path of the cookie</dd>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <dt>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen '<code>env|E=</code><em>VAR</em>:<em>VAL</em>'
c867dba1041640ecec7c8194d35a5b4ffce442earbowen (set environment variable)</dt><dd>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen This forces an environment variable named <em>VAR</em> to
c867dba1041640ecec7c8194d35a5b4ffce442earbowen be set to the value <em>VAL</em>, where <em>VAL</em> can
c867dba1041640ecec7c8194d35a5b4ffce442earbowen contain regexp backreferences (<code>$N</code> and
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <code>%N</code>) which will be expanded. You can use this
c867dba1041640ecec7c8194d35a5b4ffce442earbowen flag more than once, to set more than one variable. The
c867dba1041640ecec7c8194d35a5b4ffce442earbowen variables can later be dereferenced in many situations, most commonly
5ff4141677bb65008c01a4767bb74aa0dfb648afrbowen from within XSSI (via <code>&lt;!--#echo
c867dba1041640ecec7c8194d35a5b4ffce442earbowen var="VAR"--&gt;</code>) or CGI (<code>$ENV{'VAR'}</code>).
c867dba1041640ecec7c8194d35a5b4ffce442earbowen You can also dereference the variable in a later RewriteCond pattern, using
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <code>%{ENV:VAR}</code>. Use this to strip
c867dba1041640ecec7c8194d35a5b4ffce442earbowen information from URLs, while maintaining a record of that information.</dd>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <dt>'<code>forbidden|F</code>' (force URL
c867dba1041640ecec7c8194d35a5b4ffce442earbowen to be forbidden)</dt><dd>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen This forces the current URL to be forbidden - it immediately
c867dba1041640ecec7c8194d35a5b4ffce442earbowen sends back a HTTP response of 403 (FORBIDDEN).
c867dba1041640ecec7c8194d35a5b4ffce442earbowen Use this flag in conjunction with
c867dba1041640ecec7c8194d35a5b4ffce442earbowen appropriate RewriteConds to conditionally block some
c867dba1041640ecec7c8194d35a5b4ffce442earbowen URLs.</dd>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <dt>'<code>gone|G</code>' (force URL to be
c867dba1041640ecec7c8194d35a5b4ffce442earbowen gone)</dt><dd>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen This forces the current URL to be gone - it
c867dba1041640ecec7c8194d35a5b4ffce442earbowen immediately sends back a HTTP response of 410 (GONE). Use
c867dba1041640ecec7c8194d35a5b4ffce442earbowen this flag to mark pages which no longer exist as gone.</dd>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <dt>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen '<code>handler|H</code>=<em>Content-handler</em>'
c867dba1041640ecec7c8194d35a5b4ffce442earbowen (force Content handler)</dt><dd>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen Force the Content-handler of the target file to be
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <em>Content-handler</em>. For instance, this can be used to
c867dba1041640ecec7c8194d35a5b4ffce442earbowen simulate the <module>mod_alias</module> directive
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <directive module="mod_alias">ScriptAlias</directive>,
c867dba1041640ecec7c8194d35a5b4ffce442earbowen which internally forces all files
c867dba1041640ecec7c8194d35a5b4ffce442earbowen inside the mapped directory to have a handler of
c867dba1041640ecec7c8194d35a5b4ffce442earbowen ``<code>cgi-script</code>''.</dd>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <dt>'<code>last|L</code>'
c867dba1041640ecec7c8194d35a5b4ffce442earbowen (last rule)</dt><dd> Stop the rewriting process
c867dba1041640ecec7c8194d35a5b4ffce442earbowen here and don't apply any more rewrite rules. This corresponds
c867dba1041640ecec7c8194d35a5b4ffce442earbowen to the Perl <code>last</code> command or the
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <code>break</code> command in C. Use this flag to prevent the
c867dba1041640ecec7c8194d35a5b4ffce442earbowen currently rewritten URL from being rewritten further by
c867dba1041640ecec7c8194d35a5b4ffce442earbowen following rules. Remember, however, that if the
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <directive>RewriteRule</directive> generates an internal
11ca32a7cc125681569e8b3a95b9688ab1212990rbowen redirect (which frequently occurs when rewriting in a
11ca32a7cc125681569e8b3a95b9688ab1212990rbowen per-directory context), this will reinject the request and
11ca32a7cc125681569e8b3a95b9688ab1212990rbowen will cause processing to be repeated starting from the first
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <directive>RewriteRule</directive>.</dd>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <dt>'<code>next|N</code>'
c867dba1041640ecec7c8194d35a5b4ffce442earbowen (next round)</dt><dd>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen Re-run the rewriting process (starting again with the
c867dba1041640ecec7c8194d35a5b4ffce442earbowen first rewriting rule). This time, the URL to match is no longer
c867dba1041640ecec7c8194d35a5b4ffce442earbowen the original URL, but rather the URL returned by the last rewriting rule.
c867dba1041640ecec7c8194d35a5b4ffce442earbowen This corresponds to the Perl <code>next</code> command or
c867dba1041640ecec7c8194d35a5b4ffce442earbowen the <code>continue</code> command in C. Use
c867dba1041640ecec7c8194d35a5b4ffce442earbowen this flag to restart the rewriting process -
c867dba1041640ecec7c8194d35a5b4ffce442earbowen to immediately go to the top of the loop.
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <strong>Be careful not to create an infinite
c867dba1041640ecec7c8194d35a5b4ffce442earbowen loop!</strong></dd>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <dt>'<code>nocase|NC</code>'
c867dba1041640ecec7c8194d35a5b4ffce442earbowen (no case)</dt><dd>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen This makes the <em>Pattern</em> case-insensitive,
c867dba1041640ecec7c8194d35a5b4ffce442earbowen ignoring difference between 'A-Z' and
c867dba1041640ecec7c8194d35a5b4ffce442earbowen 'a-z' when <em>Pattern</em> is matched against the current
c867dba1041640ecec7c8194d35a5b4ffce442earbowen URL.</dd>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <dt>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen '<code>noescape|NE</code>'
c867dba1041640ecec7c8194d35a5b4ffce442earbowen (no URI escaping of
c867dba1041640ecec7c8194d35a5b4ffce442earbowen output)</dt><dd>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen This flag prevents mod_rewrite from applying the usual URI
210da88109531e6b4c9b121b4d6f15cc24bc108erbowen escaping rules to the result of a rewrite. Ordinarily,
c867dba1041640ecec7c8194d35a5b4ffce442earbowen special characters (such as '%', '$', ';', and so on)
c867dba1041640ecec7c8194d35a5b4ffce442earbowen will be escaped into their hexcode equivalents ('%25',
c867dba1041640ecec7c8194d35a5b4ffce442earbowen '%24', and '%3B', respectively); this flag prevents this
c867dba1041640ecec7c8194d35a5b4ffce442earbowen from happening. This allows percent symbols to appear in
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf the output, as in
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<example>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor RewriteRule /foo/(.*) /bar?arg=P1\%3d$1 [R,NE]
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor</example>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor which would turn '<code>/foo/zed</code>' into a safe
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor request for '<code>/bar?arg=P1=zed</code>'.
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor </dd>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <dt>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor '<code>nosubreq|NS</code>'
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor (not for internal
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor sub-requests)</dt><dd>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <p>This flag forces the rewriting engine to skip a
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor rewriting rule if the current request is an internal
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor sub-request. For instance, sub-requests occur internally
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor in Apache when <module>mod_include</module> tries to find out
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor information about possible directory default files
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor (<code>index.xxx</code> files). On sub-requests it is not
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor always useful, and can even cause errors, if
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor the complete set of rules are applied. Use this flag to
c867dba1041640ecec7c8194d35a5b4ffce442earbowen exclude some rules.</p>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <p>To decide whether or not to use this rule: if you
c867dba1041640ecec7c8194d35a5b4ffce442earbowen prefix URLs with CGI-scripts, to force them to be
c867dba1041640ecec7c8194d35a5b4ffce442earbowen processed by the CGI-script, it's likely that you
c867dba1041640ecec7c8194d35a5b4ffce442earbowen will run into problems (or significant overhead) on
c867dba1041640ecec7c8194d35a5b4ffce442earbowen sub-requests. In these cases, use this flag.</p>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen </dd>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <dt>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen '<code>proxy|P</code>' (force
c867dba1041640ecec7c8194d35a5b4ffce442earbowen proxy)</dt><dd>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen This flag forces the substitution part to be internally
c867dba1041640ecec7c8194d35a5b4ffce442earbowen sent as a proxy request and immediately (rewrite
c867dba1041640ecec7c8194d35a5b4ffce442earbowen processing stops here) put through the <a
c867dba1041640ecec7c8194d35a5b4ffce442earbowen href="mod_proxy.html">proxy module</a>. You must make
c867dba1041640ecec7c8194d35a5b4ffce442earbowen sure that the substitution string is a valid URI
c867dba1041640ecec7c8194d35a5b4ffce442earbowen (typically starting with
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <code>http://</code><em>hostname</em>) which can be
c867dba1041640ecec7c8194d35a5b4ffce442earbowen handled by the Apache proxy module. If not, you will get an
c867dba1041640ecec7c8194d35a5b4ffce442earbowen error from the proxy module. Use this flag to achieve a
c867dba1041640ecec7c8194d35a5b4ffce442earbowen more powerful implementation of the <a
c867dba1041640ecec7c8194d35a5b4ffce442earbowen href="mod_proxy.html#proxypass">ProxyPass</a> directive,
c867dba1041640ecec7c8194d35a5b4ffce442earbowen to map remote content into the namespace of the local
c867dba1041640ecec7c8194d35a5b4ffce442earbowen server.
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <p>Note: <module>mod_proxy</module> must be enabled in order
c867dba1041640ecec7c8194d35a5b4ffce442earbowen to use this flag.</p>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen </dd>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <dt>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen '<code>passthrough|PT</code>'
c867dba1041640ecec7c8194d35a5b4ffce442earbowen (pass through to next
c867dba1041640ecec7c8194d35a5b4ffce442earbowen handler)</dt><dd>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen This flag forces the rewrite engine to set the
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <code>uri</code> field of the internal
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <code>request_rec</code> structure to the value of the
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <code>filename</code> field. This flag is just a hack to
c867dba1041640ecec7c8194d35a5b4ffce442earbowen enable post-processing of the output of
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <code>RewriteRule</code> directives, using
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <code>Alias</code>, <code>ScriptAlias</code>,
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <code>Redirect</code>, and other directives from
c867dba1041640ecec7c8194d35a5b4ffce442earbowen various URI-to-filename translators. For example, to rewrite
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <code>/abc</code> to <code>/def</code> using
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <module>mod_rewrite</module>, and then
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <code>/def</code> to <code>/ghi</code> using
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <module>mod_alias</module>:
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<example>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen RewriteRule ^/abc(.*) /def$1 [PT]<br />
c867dba1041640ecec7c8194d35a5b4ffce442earbowen Alias /def /ghi
c867dba1041640ecec7c8194d35a5b4ffce442earbowen</example>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen If you omit the <code>PT</code> flag,
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <code>mod_rewrite</code> will rewrite
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <code>uri=/abc/...</code> to
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <code>filename=/def/...</code> as a full API-compliant
c867dba1041640ecec7c8194d35a5b4ffce442earbowen URI-to-filename translator should do. Then
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <code>mod_alias</code> will try to do a
c867dba1041640ecec7c8194d35a5b4ffce442earbowen URI-to-filename transition, which will fail.
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <p>Note: <strong>You must use this flag if you want to
c867dba1041640ecec7c8194d35a5b4ffce442earbowen mix directives from different modules which allow
c867dba1041640ecec7c8194d35a5b4ffce442earbowen URL-to-filename translators</strong>. The typical example
c867dba1041640ecec7c8194d35a5b4ffce442earbowen is the use of <module>mod_alias</module> and
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <module>mod_rewrite</module>.</p>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <p>The <code>PT</code> flag implies the <code>L</code> flag:
c867dba1041640ecec7c8194d35a5b4ffce442earbowen rewriting will be stopped in order to pass the request to
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf the next phase of processing.</p>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor </dd>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor <dt>'<code>qsappend|QSA</code>'
4b311579b2c8aebac85fb7cb8ac89e6c37b4bc1asf (query string
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor append)</dt><dd>
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor This flag forces the rewrite engine to append a query
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor string part of the substitution string to the existing string,
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor instead of replacing it. Use this when you want to add more
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor data to the query string via a rewrite rule.</dd>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <dt>'<code>redirect|R</code>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen [=<em>code</em>]' (force <a id="redirect"
c867dba1041640ecec7c8194d35a5b4ffce442earbowen name="redirect">redirect</a>)</dt><dd>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <p>Prefix <em>Substitution</em> with
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <code>http://thishost[:thisport]/</code> (which makes the
c867dba1041640ecec7c8194d35a5b4ffce442earbowen new URL a URI) to force a external redirection. If no
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <em>code</em> is given, a HTTP response of 302 (MOVED
c867dba1041640ecec7c8194d35a5b4ffce442earbowen TEMPORARILY) will be returned. If you want to use other
c867dba1041640ecec7c8194d35a5b4ffce442earbowen response codes, simply specify the appropriate number or use
c867dba1041640ecec7c8194d35a5b4ffce442earbowen one of the following symbolic names: <code>temp</code>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen (default), <code>permanent</code>,
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <code>seeother</code>. Use this for rules to canonicalize
c867dba1041640ecec7c8194d35a5b4ffce442earbowen the URL and return it to the client - to translate
c867dba1041640ecec7c8194d35a5b4ffce442earbowen ``<code>/~</code>'' into ``<code>/u/</code>'', or to always
c867dba1041640ecec7c8194d35a5b4ffce442earbowen append a slash to <code>/u/</code><em>user</em>, etc.<br />
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <strong>Note:</strong> When you use this flag, make sure
c867dba1041640ecec7c8194d35a5b4ffce442earbowen that the substitution field is a valid URL! Otherwise, you
c867dba1041640ecec7c8194d35a5b4ffce442earbowen will be redirecting to an invalid location. Remember that
c867dba1041640ecec7c8194d35a5b4ffce442earbowen this flag on its own will only prepend
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <code>http://thishost[:thisport]/</code> to the URL, and
c867dba1041640ecec7c8194d35a5b4ffce442earbowen rewriting will continue. Usually, you will want to stop
c867dba1041640ecec7c8194d35a5b4ffce442earbowen rewriting at this point, and redirect immediately. To stop
c867dba1041640ecec7c8194d35a5b4ffce442earbowen rewriting, you should add the 'L' flag.</p>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <p>While this is typically used for redirects, any valid status
c867dba1041640ecec7c8194d35a5b4ffce442earbowen code can be given here. If the status code is outside the redirect
c867dba1041640ecec7c8194d35a5b4ffce442earbowen range (300-399), then the <em>Substitution</em> string is dropped
c867dba1041640ecec7c8194d35a5b4ffce442earbowen and rewriting is stopped as if the <code>L</code> flag was
c867dba1041640ecec7c8194d35a5b4ffce442earbowen used.</p>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen </dd>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <dt>'<code>skip|S</code>=<em>num</em>'
c867dba1041640ecec7c8194d35a5b4ffce442earbowen (skip next rule(s))</dt><dd>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen This flag forces the rewriting engine to skip the next
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <em>num</em> rules in sequence, if the current rule
c867dba1041640ecec7c8194d35a5b4ffce442earbowen matches. Use this to make pseudo if-then-else constructs:
c867dba1041640ecec7c8194d35a5b4ffce442earbowen The last rule of the then-clause becomes
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <code>skip=N</code>, where N is the number of rules in the
c867dba1041640ecec7c8194d35a5b4ffce442earbowen else-clause. (This is <strong>not</strong> the same as the
c867dba1041640ecec7c8194d35a5b4ffce442earbowen 'chain|C' flag!)</dd>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <dt>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen '<code>type|T</code>=<em>MIME-type</em>'
c867dba1041640ecec7c8194d35a5b4ffce442earbowen (force MIME type)</dt><dd>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen Force the <glossary>MIME-type</glossary> of the target file to be
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <em>MIME-type</em>. This can be used to
c867dba1041640ecec7c8194d35a5b4ffce442earbowen set up the content-type based on some conditions.
c867dba1041640ecec7c8194d35a5b4ffce442earbowen For example, the following snippet allows <code>.php</code> files to
c867dba1041640ecec7c8194d35a5b4ffce442earbowen be <em>displayed</em> by <code>mod_php</code> if they are called with
c867dba1041640ecec7c8194d35a5b4ffce442earbowen the <code>.phps</code> extension:
c867dba1041640ecec7c8194d35a5b4ffce442earbowen <example>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen RewriteRule ^(.+\.php)s$ $1 [T=application/x-httpd-php-source]
c867dba1041640ecec7c8194d35a5b4ffce442earbowen </example>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen </dd>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen </dl>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<note><title>Per-directory Rewrites</title>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<p>The rewrite engine may be used in <a
c867dba1041640ecec7c8194d35a5b4ffce442earbowenhref="/howto/htaccess.html">.htaccess</a> files. To enable the
c867dba1041640ecec7c8194d35a5b4ffce442earbowenrewrite engine for these files you need to set
c867dba1041640ecec7c8194d35a5b4ffce442earbowen"<code>RewriteEngine On</code>" <strong>and</strong>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen"<code>Options FollowSymLinks</code>" must be enabled. If your
c867dba1041640ecec7c8194d35a5b4ffce442earbowenadministrator has disabled override of <code>FollowSymLinks</code> for
c867dba1041640ecec7c8194d35a5b4ffce442earbowena user's directory, then you cannot use the rewrite engine. This
c867dba1041640ecec7c8194d35a5b4ffce442earbowenrestriction is required for security reasons.</p>
c867dba1041640ecec7c8194d35a5b4ffce442earbowen
c867dba1041640ecec7c8194d35a5b4ffce442earbowen<p>When using the rewrite engine in <code>.htaccess</code> files the
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzorper-directory prefix (which always is the same for a specific
c867dba1041640ecec7c8194d35a5b4ffce442earbowendirectory) is automatically <em>removed</em> for the pattern matching
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzorand automatically <em>added</em> after the substitution has been
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzordone. This feature is essential for many sorts of rewriting; without
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzorthis, you would always have to match the parent directory, which is
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzornot always possible. There is one exception: If a substitution string
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzorstarts with <code>http://</code>, then the directory prefix will
dc3a272f8afcbc137adcfee4c3aa052d2bdf4df7gryzor<strong>not</strong> be added, and an external redirect (or proxy
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjungthroughput, if using flag <strong>P</strong>) is forced. See the
727872d18412fc021f03969b8641810d8896820bhumbedooh<directive module="mod_rewrite">RewriteBase</directive> directive for
0d0ba3a410038e179b695446bb149cce6264e0abndmore information.</p>
727872d18412fc021f03969b8641810d8896820bhumbedooh
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh<p>The rewrite engine may also be used in <directive type="section"
0d0ba3a410038e179b695446bb149cce6264e0abndmodule="core">Directory</directive> sections with the same
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedoohprefix-matching rules as would be applied to <code>.htaccess</code>
727872d18412fc021f03969b8641810d8896820bhumbedoohfiles. It is usually simpler, however, to avoid the prefix substitution
0d0ba3a410038e179b695446bb149cce6264e0abndcomplication by putting the rewrite rules in the main server or
0d0ba3a410038e179b695446bb149cce6264e0abndvirtual host context, rather than in a <directive type="section"
0d0ba3a410038e179b695446bb149cce6264e0abndmodule="core">Directory</directive> section.</p>
ac082aefa89416cbdc9a1836eaf3bed9698201c8humbedooh
0d0ba3a410038e179b695446bb149cce6264e0abnd<p>Although rewrite rules are syntactically permitted in <directive
0d0ba3a410038e179b695446bb149cce6264e0abndtype="section" module="core">Location</directive> sections, this
0d0ba3a410038e179b695446bb149cce6264e0abndshould never be necessary and is unsupported.</p>
727872d18412fc021f03969b8641810d8896820bhumbedooh
0d0ba3a410038e179b695446bb149cce6264e0abnd</note>
0d0ba3a410038e179b695446bb149cce6264e0abnd
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh <p>Here are all possible substitution combinations and their
1a1356f375e36db7bee379ea0684ab389579f798rbowen meanings:</p>
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen
0d0ba3a410038e179b695446bb149cce6264e0abnd <p><strong>Inside per-server configuration
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd (<code>httpd.conf</code>)<br />
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd for request ``<code>GET
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd /somepath/pathinfo</code>'':</strong><br />
bc9d4698fce0238d2f6f2682e99423ebb1149976rbowen </p>
<note><pre>
<strong>Given Rule</strong> <strong>Resulting Substitution</strong>
---------------------------------------------- ----------------------------------
^/somepath(.*) otherpath$1 invalid, not supported
^/somepath(.*) otherpath$1 [R] invalid, not supported
^/somepath(.*) otherpath$1 [P] invalid, not supported
---------------------------------------------- ----------------------------------
^/somepath(.*) /otherpath$1 /otherpath/pathinfo
^/somepath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
via external redirection
^/somepath(.*) /otherpath$1 [P] doesn't make sense, not supported
---------------------------------------------- ----------------------------------
^/somepath(.*) http://thishost/otherpath$1 /otherpath/pathinfo
^/somepath(.*) http://thishost/otherpath$1 [R] http://thishost/otherpath/pathinfo
via external redirection
^/somepath(.*) http://thishost/otherpath$1 [P] doesn't make sense, not supported
---------------------------------------------- ----------------------------------
^/somepath(.*) http://otherhost/otherpath$1 http://otherhost/otherpath/pathinfo
via external redirection
^/somepath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfo
via external redirection
(the [R] flag is redundant)
^/somepath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfo
via internal proxy
</pre></note>
<p><strong>Inside per-directory configuration for
<code>/somepath</code><br />
(<code>/physical/path/to/somepath/.htacccess</code>, with
<code>RewriteBase /somepath</code>)<br />
for request ``<code>GET
/somepath/localpath/pathinfo</code>'':</strong><br />
</p>
<note><pre>
<strong>Given Rule</strong> <strong>Resulting Substitution</strong>
---------------------------------------------- ----------------------------------
^localpath(.*) otherpath$1 /somepath/otherpath/pathinfo
^localpath(.*) otherpath$1 [R] http://thishost/somepath/otherpath/pathinfo
via external redirection
^localpath(.*) otherpath$1 [P] doesn't make sense, not supported
---------------------------------------------- ----------------------------------
^localpath(.*) /otherpath$1 /otherpath/pathinfo
^localpath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
via external redirection
^localpath(.*) /otherpath$1 [P] doesn't make sense, not supported
---------------------------------------------- ----------------------------------
^localpath(.*) http://thishost/otherpath$1 /otherpath/pathinfo
^localpath(.*) http://thishost/otherpath$1 [R] http://thishost/otherpath/pathinfo
via external redirection
^localpath(.*) http://thishost/otherpath$1 [P] doesn't make sense, not supported
---------------------------------------------- ----------------------------------
^localpath(.*) http://otherhost/otherpath$1 http://otherhost/otherpath/pathinfo
via external redirection
^localpath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfo
via external redirection
(the [R] flag is redundant)
^localpath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfo
via internal proxy
</pre></note>
</usage>
</directivesynopsis>
</modulesynopsis>