mod_rewrite.xml revision 45309cf90ecc60d20e1ac810881e7b149fbe4e35
013e1ddd21f2142a369c9a9a0eeb6c6a0bc3fcf3patrikj<!DOCTYPE modulesynopsis SYSTEM "/style/modulesynopsis.dtd">
e942c741056732f50da2074b36fe59805d370650slive<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
5f5d1b4cc970b7f06ff8ef6526128e9a27303d88nd<!-- $LastChangedRevision$ -->
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding Licensed to the Apache Software Foundation (ASF) under one or more
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding contributor license agreements. See the NOTICE file distributed with
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding this work for additional information regarding copyright ownership.
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding The ASF licenses this file to You under the Apache License, Version 2.0
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding (the "License"); you may not use this file except in compliance with
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding the License. You may obtain a copy of the License at
d5d794fc2f4cc9ca6d6da17cfa2cdcd8d244bacdnd Unless required by applicable law or agreed to in writing, software
d5d794fc2f4cc9ca6d6da17cfa2cdcd8d244bacdnd distributed under the License is distributed on an "AS IS" BASIS,
d5d794fc2f4cc9ca6d6da17cfa2cdcd8d244bacdnd WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d5d794fc2f4cc9ca6d6da17cfa2cdcd8d244bacdnd See the License for the specific language governing permissions and
d5d794fc2f4cc9ca6d6da17cfa2cdcd8d244bacdnd limitations under the License.
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<description>Provides a rule-based rewriting engine to rewrite requested
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfsliveURLs on the fly</description>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<compatibility>Available in Apache 1.3 and later</compatibility>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p>This module uses a rule-based rewriting engine (based on a
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive regular-expression parser) to rewrite requested URLs on the
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive fly. It supports an unlimited number of rules and an
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin unlimited number of attached rule conditions for each rule, to
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive provide a really flexible and powerful URL manipulation
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive mechanism. The URL manipulations can depend on various tests,
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin of server variables, environment variables, HTTP
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin headers, or time stamps. Even external database lookups in
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin various formats can be used to achieve highly granular URL
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive matching.</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p>This module operates on the full URLs (including the
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive path-info part) both in per-server context
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin (<code>.htaccess</code>) and can generate query-string
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive parts on result. The rewritten result can lead to internal
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive sub-processing, external request redirection or even to an
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive internal proxy throughput.</p>
f0a393c5c2d7de58f447855369ad2fbfa254e544rbowen <p>Further details, discussion, and examples, are provided in the
f0a393c5c2d7de58f447855369ad2fbfa254e544rbowen <a href="/rewrite/">detailed mod_rewrite documentation</a>.</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<section id="quoting"><title>Quoting Special Characters</title>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p>As of Apache 1.3.20, special characters in
013e1ddd21f2142a369c9a9a0eeb6c6a0bc3fcf3patrikj <em>TestString</em> and <em>Substitution</em> strings can be
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive escaped (that is, treated as normal characters without their
f6aae3e0ce2de5bd8a6809edf85832ad915fe94crbowen usual special meaning) by prefixing them with a slash ('\')
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive character. In other words, you can include an actual
013e1ddd21f2142a369c9a9a0eeb6c6a0bc3fcf3patrikj dollar-sign character in a <em>Substitution</em> string by
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive using '<code>\$</code>'; this keeps mod_rewrite from trying
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive to treat it as a backreference.</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<section id="EnvVar"><title>Environment Variables</title>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p>This module keeps track of two additional (non-standard)
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive CGI/SSI environment variables named <code>SCRIPT_URL</code>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <em>logical</em> Web-view to the current resource, while the
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive standard CGI/SSI variables <code>SCRIPT_NAME</code> and
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <code>SCRIPT_FILENAME</code> contain the <em>physical</em>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive System-view. </p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p>Notice: These variables hold the URI/URL <em>as they were
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin initially requested</em>, that is, <em>before</em> any
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin rewriting. This is important to note because the rewriting process is
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive primarily used to rewrite logical URLs to physical
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive pathnames.</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfsliveSCRIPT_NAME=/sw/lib/w3s/tree/global/u/rse/.www/index.html
4c36c711036219c80d5517d35be68a4769c15291slive<section id="vhosts"><title>Rewriting in Virtual Hosts</title>
4c36c711036219c80d5517d35be68a4769c15291slive <p>By default, <module>mod_rewrite</module> configuration
4c36c711036219c80d5517d35be68a4769c15291slive settings from the main server context are not inherited by
4c36c711036219c80d5517d35be68a4769c15291slive virtual hosts. To make the main server settings apply to virtual
4c36c711036219c80d5517d35be68a4769c15291slive hosts, you must place the following directives in each <directive
4c36c711036219c80d5517d35be68a4769c15291slive module="core" type="section">VirtualHost</directive> section:</p>
4c36c711036219c80d5517d35be68a4769c15291slive RewriteEngine On<br />
f736cd11585a35572d5f42accf026eb667848434slive RewriteOptions Inherit
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<section id="Solutions"><title>Practical Solutions</title>
f0a393c5c2d7de58f447855369ad2fbfa254e544rbowen <p>For numerous examples of common, and not-so-common, uses for
f0a393c5c2d7de58f447855369ad2fbfa254e544rbowen mod_rewrite, see the <a href="/rewrite/rewrite_guide.html">Rewrite
f0a393c5c2d7de58f447855369ad2fbfa254e544rbowen href="/rewrite/rewrite_guide_advanced.html">Advanced Rewrite
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<directivesynopsis>
013e1ddd21f2142a369c9a9a0eeb6c6a0bc3fcf3patrikj<description>Enables or disables runtime rewriting engine</description>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<contextlist><context>server config</context><context>virtual host</context>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<context>directory</context><context>.htaccess</context></contextlist>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p>The <directive>RewriteEngine</directive> directive enables or
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive disables the runtime rewriting engine. If it is set to
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <code>off</code> this module does no runtime processing at
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive all. It does not even update the <code>SCRIPT_URx</code>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive environment variables.</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p>Use this directive to disable the module instead of
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive commenting out all the <directive
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive module="mod_rewrite">RewriteRule</directive> directives!</p>
4c36c711036219c80d5517d35be68a4769c15291slive <p>Note that rewrite configurations are not
4c36c711036219c80d5517d35be68a4769c15291slive inherited by virtual hosts. This means that you need to have a
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <code>RewriteEngine on</code> directive for each virtual host
4c36c711036219c80d5517d35be68a4769c15291slive in which you wish to use rewrite rules.</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive</directivesynopsis>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<directivesynopsis>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<description>Sets some special options for the rewrite engine</description>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<contextlist><context>server config</context><context>virtual host</context>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<context>directory</context><context>.htaccess</context></contextlist>
1d7d4ad3081da9e2bc11611ddccdf68f89e8baf9nd<compatibility><code>MaxRedirects</code> is no longer available in version 2.1 and
9ed9ba1fcf0a4a39f78f5f809c661bbd590b70eandlater</compatibility>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p>The <directive>RewriteOptions</directive> directive sets some
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive special options for the current per-server or per-directory
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin configuration. The <em>Option</em> string can currently
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin only be one of the following:</p>
9ed9ba1fcf0a4a39f78f5f809c661bbd590b70eand <dd>This forces the current configuration to inherit the
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin configuration of the parent. In per-virtual-server context,
9ed9ba1fcf0a4a39f78f5f809c661bbd590b70eand this means that the maps, conditions and rules of the main
9ed9ba1fcf0a4a39f78f5f809c661bbd590b70eand server are inherited. In per-directory context this means
9ed9ba1fcf0a4a39f78f5f809c661bbd590b70eand that conditions and rules of the parent directory's
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive</directivesynopsis>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<directivesynopsis>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<description>Sets the name of the file used for logging rewrite engine
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfsliveprocessing</description>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<contextlist><context>server config</context><context>virtual host</context>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive</contextlist>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p>The <directive>RewriteLog</directive> directive sets the name
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive of the file to which the server logs any rewriting actions it
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive performs. If the name does not begin with a slash
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive ('<code>/</code>') then it is assumed to be relative to the
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <em>Server Root</em>. The directive should occur only once per
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive server config.</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<note> To disable the logging of
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive rewriting actions it is not recommended to set
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive although the rewriting engine does not then output to a
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive logfile it still creates the logfile output internally.
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <strong>This will slow down the server with no advantage
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive to the administrator!</strong> To disable logging either
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive remove or comment out the <directive>RewriteLog</directive>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfsliveSee the <a href="/misc/security_tips.html">Apache Security Tips</a>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirindocument for details on how your security could be compromised if the
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslivedirectory where logfiles are stored is writable by anyone other than
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslivethe user that starts the server.
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive</directivesynopsis>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<directivesynopsis>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<description>Sets the verbosity of the log file used by the rewrite
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfsliveengine</description>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<contextlist><context>server config</context><context>virtual host</context>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive</contextlist>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p>The <directive>RewriteLogLevel</directive> directive sets the
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive verbosity level of the rewriting logfile. The default level 0
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive means no logging, while 9 or more means that practically all
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive actions are logged.</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p>To disable the logging of rewriting actions simply set
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<note> Using a high value for
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive dramatically! Use the rewriting logfile at a
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfsliveRewriteLogLevel 3
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive</directivesynopsis>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<directivesynopsis>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<description>Sets the name of the lock file used for <directive
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslivesynchronization</description>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<contextlist><context>server config</context></contextlist>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p>This directive sets the filename for a synchronization
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive lockfile which mod_rewrite needs to communicate with <directive
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <em>programs</em>. Set this lockfile to a local path (not on a
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive NFS-mounted device) when you want to use a rewriting
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive map-program. It is not required for other types of rewriting
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive</directivesynopsis>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<directivesynopsis>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<description>Defines a mapping function for key-lookup</description>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<syntax>RewriteMap <em>MapName</em> <em>MapType</em>:<em>MapSource</em>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<contextlist><context>server config</context><context>virtual host</context>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive</contextlist>
630c456b6461158be6cc5c5483735e27b13b4ad5nd<compatibility>The choice of different dbm types is available in
630c456b6461158be6cc5c5483735e27b13b4ad5ndApache 2.0.41 and later</compatibility>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p>The <directive>RewriteMap</directive> directive defines a
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive substitution strings by the mapping-functions to
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive insert/substitute fields through a key lookup. The source of
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive this lookup can be of various types.</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p>The <a id="mapfunc" name="mapfunc"><em>MapName</em></a> is
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive the name of the map and will be used to specify a
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive mapping-function for the substitution strings of a rewriting
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive rule via one of the following constructs:</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <strong><code>${</code> <em>MapName</em> <code>:</code>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <em>LookupKey</em> <code>|</code> <em>DefaultValue</em>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <p>When such a construct occurs, the map <em>MapName</em> is
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive consulted and the key <em>LookupKey</em> is looked-up. If the
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive key is found, the map-function construct is substituted by
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <em>SubstValue</em>. If the key is not found then it is
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive substituted by <em>DefaultValue</em> or by the empty string
ee73c32ad65734a6514bcbd0ed6e20494e8a50bdrbowen <p>For example, you might define a
ee73c32ad65734a6514bcbd0ed6e20494e8a50bdrbowen <p>You would then be able to use this map in a
8ac3ff7008df949c096f9cd8f769c7893594f61fnd RewriteRule ^/ex/(.*) ${examplemap:$1}
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p>The following combinations for <em>MapType</em> and
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive path to valid regular file
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p>This is the standard rewriting map feature where the
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive either blank lines, comment lines (starting with a '#'
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive character) or pairs like the following - one per
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive## map.txt -- rewriting map
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfsliveRalf.S.Engelschall rse # Bastard Operator From Hell
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfsliveMr.Joe.Average joe # Mr. Average
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive path to valid regular file
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p>This is identical to the Standard Plain Text variant
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive above but with a special post-processing feature: After
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive looking up a value it is parsed according to contained
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive ``<code>|</code>'' characters which have the meaning of
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive ``or''. In other words they indicate a set of
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive alternatives from which the actual returned value is
36088d24dae5b2cc8124264fc6a9ba349ba81adcrbowen chosen randomly. For example, you might use the following map
36088d24dae5b2cc8124264fc6a9ba349ba81adcrbowen file and directives to provide a random load balancing between
36088d24dae5b2cc8124264fc6a9ba349ba81adcrbowen several back-end server, via a reverse-proxy. Images are sent
36088d24dae5b2cc8124264fc6a9ba349ba81adcrbowen to one of the servers in the 'static' pool, while everything
36088d24dae5b2cc8124264fc6a9ba349ba81adcrbowen else is sent to one of the 'dynamic' pool.</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive## map.txt -- rewriting map
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslivestatic www1|www2|www3|www4
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslivedynamic www5|www6
36088d24dae5b2cc8124264fc6a9ba349ba81adcrbowenRewriteRule ^/(.*\.(png|gif|jpg)) http://${servers:static}/$1
36088d24dae5b2cc8124264fc6a9ba349ba81adcrbowen[NC,P,L]<br />
36088d24dae5b2cc8124264fc6a9ba349ba81adcrbowenRewriteRule ^/(.*) http://${servers:dynamic}/$1 [P,L]
1578daeec017d3bb20cecdcdc3b0261c999730d5slive <code>dbm[=<em>type</em>]</code>, MapSource: Unix filesystem
1578daeec017d3bb20cecdcdc3b0261c999730d5slive path to valid regular file
1578daeec017d3bb20cecdcdc3b0261c999730d5slive <p>Here the source is a binary format DBM file containing
1578daeec017d3bb20cecdcdc3b0261c999730d5slive the same contents as a <em>Plain Text</em> format file, but
1578daeec017d3bb20cecdcdc3b0261c999730d5slive in a special representation which is optimized for really
1578daeec017d3bb20cecdcdc3b0261c999730d5slive fast lookups. The <em>type</em> can be sdbm, gdbm, ndbm, or
1578daeec017d3bb20cecdcdc3b0261c999730d5slive db depending on <a href="/install.html#dbm">compile-time
9f7f8f89dfb9115b0b9493049a6ca1ecd8508242rbowen compile-time default will be chosen.</p>
9f7f8f89dfb9115b0b9493049a6ca1ecd8508242rbowen <p>To create a dbm file from a source text file, use the <a
9f7f8f89dfb9115b0b9493049a6ca1ecd8508242rbowen href="/programs/httxt2dbm.html">httxt2dbm</a> utility.</p>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <p>Here, the source is an internal Apache function.
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive Currently you cannot create your own, but the following
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin functions already exist:</p>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Converts the key to all upper case.</li>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Converts the key to all lower case.</li>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Translates special characters in the key to
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive hex-encodings.</li>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Translates hex-encodings in the key back to
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive special characters.</li>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive path to valid regular file
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p>Here the source is a program, not a map file. To
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin create it you can use a language of your choice, but
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin the result has to be an executable program (either
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive object-code or a script with the magic cookie trick
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <p>This program is started once, when the Apache server
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin is started, and then communicates with the rewriting engine
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive file-handles. For each map-function lookup it will
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive receive the key to lookup as a newline-terminated string
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive looked-up value as a newline-terminated string on
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive ``<code>NULL</code>'' if it fails (<em>i.e.</em>, there
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive is no corresponding value for the given key). A trivial
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive program which will implement a 1:1 map (<em>i.e.</em>,
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive key == value) could be:</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslivewhile (<STDIN>) {
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive # ...put here any transformations or lookups...
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin If this program hangs, it will cause Apache to hang
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin when trying to use the relevant rewrite rule.</li>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <li>A common mistake is to use buffered I/O on
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <code>stdout</code>. Avoid this, as it will cause a deadloop!
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin ``<code>$|=1</code>'' is used above, to prevent this.</li>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin module="mod_rewrite">RewriteLock</directive> directive can
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin be used to define a lockfile which mod_rewrite can use to synchronize
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin communication with the mapping program. By default no such
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive synchronization takes place.</li>
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniq MapSource: An SQL SELECT statement that takes a single
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniq argument and returns a single value.</p>
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniq <p>This uses <module>mod_dbd</module> to implement a rewritemap
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniq by lookup in an SQL database. There are two forms:
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniq <code>fastdbd</code> caches database lookups internally,
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniq performance penalty but responds immediately if the database
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniq contents are updated, while <code>fastdbd</code> is more
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniq efficient but won't re-read database contents until server
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniq restart.</p>
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniq <p>If a query returns more than one row, a random row from
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniq the result set is used.</p>
1b27a3a26f18191db7ecb4d536cb121ba9520a8eniqRewriteMap myquery "fastdbd:SELECT destination FROM rewrite WHERE source = %s"
013e1ddd21f2142a369c9a9a0eeb6c6a0bc3fcf3patrikj <p>The <directive>RewriteMap</directive> directive can occur more than
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive once. For each mapping-function use one
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <directive>RewriteMap</directive> directive to declare its rewriting
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive mapfile. While you cannot <strong>declare</strong> a map in
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive per-directory context it is of course possible to
013e1ddd21f2142a369c9a9a0eeb6c6a0bc3fcf3patrikj <strong>use</strong> this map in per-directory context. </p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<note><title>Note</title> For plain text and DBM format files the
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslivelooked-up keys are cached in-core until the <code>mtime</code> of the
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslivemapfile changes or the server does a restart. This way you can have
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslivemap-functions in rules which are used for <strong>every</strong>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfsliverequest. This is no problem, because the external lookup only happens
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive</directivesynopsis>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<directivesynopsis>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<description>Sets the base URL for per-directory rewrites</description>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<contextlist><context>directory</context><context>.htaccess</context>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive</contextlist>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p>The <directive>RewriteBase</directive> directive explicitly
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive sets the base URL for per-directory rewrites. As you will see
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive below, <directive module="mod_rewrite">RewriteRule</directive>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive can be used in per-directory config files
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin (<code>.htaccess</code>). In such a case, it will act locally,
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin stripping the local directory prefix before processing, and applying
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin rewrite rules only to the remainder. When processing is complete, the
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin prefix is automatically added back to the
013e1ddd21f2142a369c9a9a0eeb6c6a0bc3fcf3patrikj path. The default setting is; <directive>RewriteBase</directive> <em>physical-directory-path</em></p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p>When a substitution occurs for a new URL, this module has
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive to re-inject the URL into the server processing. To be able
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive to do this it needs to know what the corresponding URL-prefix
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive or URL-base is. By default this prefix is the corresponding
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin filepath itself. <strong>However, for most websites, URLs are NOT
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive directly related to physical filename paths, so this
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin assumption will often be wrong!</strong> Therefore, you can
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive use the <code>RewriteBase</code> directive to specify the
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive correct URL-prefix.</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<note> If your webserver's URLs are <strong>not</strong> directly
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirinrelated to physical file paths, you will need to use
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<directive>RewriteBase</directive> in every <code>.htaccess</code>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirinfile where you want to use <directive
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslivemodule="mod_rewrite">RewriteRule</directive> directives.
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p> For example, assume the following per-directory config file:</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive# /abc/def/.htaccess -- per-dir config file for directory /abc/def
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive# Remember: /abc/def is the physical path of /xyz, <em>i.e.</em>, the server
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfsliveRewriteEngine On
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive# let the server know that we were reached via /xyz and not
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfsliveRewriteBase /xyz
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive# now the rewriting rules
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfsliveRewriteRule ^oldstuff\.html$ newstuff.html
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p>In the above example, a request to
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <code>/xyz/oldstuff.html</code> gets correctly rewritten to
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive the physical file <code>/abc/def/newstuff.html</code>.</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<p>The following list gives detailed information about
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive the internal processing steps:</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfsliveInternal Processing:
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive /xyz/oldstuff.html -> /abc/def/oldstuff.html (per-server Alias)
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive /abc/def/oldstuff.html -> /abc/def/newstuff.html (per-dir RewriteRule)
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive /abc/def/newstuff.html -> /xyz/newstuff.html (per-dir RewriteBase)
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive /xyz/newstuff.html -> /abc/def/newstuff.html (per-server Alias)
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <p>This seems very complicated, but is in fact
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin correct Apache internal processing. Because the
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin per-directory rewriting comes late in the
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin process, the rewritten request
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin has to be re-injected into the Apache kernel.
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin This is not the serious overhead it may seem to be -
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin this re-injection is completely internal to the
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Apache server (and the same procedure is used by
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin many other operations within Apache).</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive</directivesynopsis>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<directivesynopsis>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<description>Defines a condition under which rewriting will take place
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive</description>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<syntax> RewriteCond
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<contextlist><context>server config</context><context>virtual host</context>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<context>directory</context><context>.htaccess</context></contextlist>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p>The <directive>RewriteCond</directive> directive defines a
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin rule condition. One or more <directive>RewriteCond</directive>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin can precede a <directive module="mod_rewrite">RewriteRule</directive>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin directive. The following rule is then only used if both
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin the current state of the URI matches its pattern, <strong
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <p><em>TestString</em> is a string which can contain the
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive following expanded constructs in addition to plain text:</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <strong>RewriteRule backreferences</strong>: These are
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin backreferences of the form <strong><code>$N</code></strong>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin (0 <= N <= 9), which provide access to the grouped
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin parts (in parentheses) of the pattern, from the
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <code>RewriteRule</code> which is subject to the current
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <strong>RewriteCond backreferences</strong>: These are
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin backreferences of the form <strong><code>%N</code></strong>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin (1 <= N <= 9), which provide access to the grouped
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin parts (again, in parentheses) of the pattern, from the last matched
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive of conditions.
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive RewriteMap</a> for more details.
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <strong>Server-Variables</strong>: These are variables of
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive from the following list:
97a9a944b5887e91042b019776c41d5dd74557aferikabele <th>HTTP headers:</th> <th>connection & request:</th> <th></th>
97a9a944b5887e91042b019776c41d5dd74557aferikabele HTTP_USER_AGENT<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive HTTP_REFERER<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive HTTP_COOKIE<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive HTTP_FORWARDED<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive HTTP_HOST<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive HTTP_PROXY_CONNECTION<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive HTTP_ACCEPT<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele REMOTE_ADDR<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive REMOTE_HOST<br />
74a6de79356cd15d2e47065087785e36dd65aa41nd REMOTE_PORT<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive REMOTE_USER<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive REMOTE_IDENT<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive REQUEST_METHOD<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive SCRIPT_FILENAME<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive PATH_INFO<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive QUERY_STRING<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive AUTH_TYPE<br />
53d2fd50ff45e7c568f0588c742a5ef9edf8e275rbowen <th>server internals:</th> <th>date and time:</th> <th>specials:</th>
97a9a944b5887e91042b019776c41d5dd74557aferikabele DOCUMENT_ROOT<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive SERVER_ADMIN<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive SERVER_NAME<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive SERVER_ADDR<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive SERVER_PORT<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive SERVER_PROTOCOL<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive SERVER_SOFTWARE<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele TIME_YEAR<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive TIME_MON<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive TIME_DAY<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive TIME_HOUR<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive TIME_MIN<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive TIME_SEC<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive TIME_WDAY<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele API_VERSION<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive THE_REQUEST<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive REQUEST_URI<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive REQUEST_FILENAME<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive IS_SUBREQ<br />
fb82af0f0cd7b58eef19c54b086131b7e1e1e749madhum HTTPS<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p>These variables all
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive correspond to the similarly named HTTP
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive MIME-headers, C variables of the Apache server or
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive Most are documented elsewhere in the Manual or in
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive the CGI specification. Those that are special to
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin mod_rewrite include those below.</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <dd>Will contain the text "true" if the request
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive currently being processed is a sub-request,
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive "false" otherwise. Sub-requests may be generated
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive by modules that need to resolve additional files
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive or URIs in order to complete their tasks.</dd>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <dd>This is the version of the Apache module API
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive (the internal interface between server and
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive module) in the current httpd build, as defined in
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive corresponds to the version of Apache in use (in
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive the release version of Apache 1.3.14, for
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive instance, it is 19990320:10), but is mainly of
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive interest to module authors.</dd>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <dd>The full HTTP request line sent by the
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive include any additional headers sent by the
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive browser.</dd>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <dd>The resource requested in the HTTP request
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive line. (In the example above, this would be
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <dd>The full local filesystem path to the file or
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive script matching the request.</dd>
7748a5c411233f9e1f3df10ea5fffffa91e58824jorton <dd>Will contain the text "on" if the connection is
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin can be safely used regardless of whether or not
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <li>The variables SCRIPT_FILENAME and REQUEST_FILENAME
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin contain the same value - the value of the
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <code>request_rec</code> structure of the Apache server.
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin The first name is the commonly known CGI variable name
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin while the second is the appropriate counterpart of
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive REQUEST_URI (which contains the value of the
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <code>uri</code> field of <code>request_rec</code>).</li>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <code>%{ENV:variable}</code>, where <em>variable</em> can be
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin any environment variable, is also available.
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin This is looked-up via internal
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive Apache structures and (if not found there) via
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <code>getenv()</code> from the Apache server process.</li>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <code>%{SSL:variable}</code>, where <em>variable</em> is the
7748a5c411233f9e1f3df10ea5fffffa91e58824jorton name of an <a href="mod_ssl.html#envvars">SSL environment
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin variable</a>, can be used whether or not
7748a5c411233f9e1f3df10ea5fffffa91e58824jorton <module>mod_ssl</module> is loaded, but will always expand to
7748a5c411233f9e1f3df10ea5fffffa91e58824jorton the empty string if it is not. Example:
7748a5c411233f9e1f3df10ea5fffffa91e58824jorton <code>%{SSL:SSL_CIPHER_USEKEYSIZE}</code> may expand to
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <code>%{HTTP:header}</code>, where <em>header</em> can be
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin any HTTP MIME-header name, can always be used to obtain the
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin value of a header sent in the HTTP request.
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive the value of the HTTP header
b65a184929c97d0b0e4d3bad42648e0e9ce1b8ferpluem <p>If a HTTP header is used in a condition this header is added to
b65a184929c97d0b0e4d3bad42648e0e9ce1b8ferpluem the Vary header of the response in case the condition evaluates to
b65a184929c97d0b0e4d3bad42648e0e9ce1b8ferpluem to true for the request. It is <strong>not</strong> added if the
b65a184929c97d0b0e4d3bad42648e0e9ce1b8ferpluem condition evaluates to false for the request. Adding the HTTP header
b65a184929c97d0b0e4d3bad42648e0e9ce1b8ferpluem to the Vary header of the response is needed for proper caching.</p>
b65a184929c97d0b0e4d3bad42648e0e9ce1b8ferpluem <p>It has to be kept in mind that conditions follow a short circuit
b65a184929c97d0b0e4d3bad42648e0e9ce1b8ferpluem logic in the case of the '<strong><code>ornext|OR</code></strong>' flag
b65a184929c97d0b0e4d3bad42648e0e9ce1b8ferpluem so that certain conditions might not be evaluated at all.</p></li>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <code>%{LA-U:variable}</code> can be used for look-aheads which perform
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive an internal (URL-based) sub-request to determine the final
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin value of <em>variable</em>. This can be used to access
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin variable for rewriting which is not available at the current
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin stage, but will be set in a later phase.
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <p>For instance, to rewrite according to the
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin per-server context (<code>httpd.conf</code> file) you must
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin variable is set by the authorization phases, which come
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <em>after</em> the URL translation phase (during which mod_rewrite
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin operates).</p>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <p>On the other hand, because mod_rewrite implements
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive its per-directory context (<code>.htaccess</code> file) via
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive the Fixup phase of the API and because the authorization
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive phases come <em>before</em> this phase, you just can use
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <code>%{REMOTE_USER}</code> in that context.</p></li>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <code>%{LA-F:variable}</code> can be used to perform an internal
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin (filename-based) sub-request, to determine the final value
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin of <em>variable</em>. Most of the time, this is the same as
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive LA-U above.</li>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin a regular expression which is applied to the
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <em>TestString</em> is first evaluated, before being matched against
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p><strong>Remember:</strong> <em>CondPattern</em> is a
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive additions:</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <li>You can prefix the pattern string with a
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive '<code>!</code>' character (exclamation mark) to specify a
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive There are some special variants of <em>CondPatterns</em>.
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive Instead of real regular expression strings you can also
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive use one of the following:
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <li>'<strong><CondPattern</strong>' (lexicographically
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin precedes)<br />
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Treats the <em>CondPattern</em> as a plain string and
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin compares it lexicographically to <em>TestString</em>. True if
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <li>'<strong>>CondPattern</strong>' (lexicographically
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin follows)<br />
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Treats the <em>CondPattern</em> as a plain string and
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin compares it lexicographically to <em>TestString</em>. True if
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <li>'<strong>=CondPattern</strong>' (lexicographically
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive equal)<br />
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Treats the <em>CondPattern</em> as a plain string and
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin compares it lexicographically to <em>TestString</em>. True if
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin equal, character for character). If <em>CondPattern</em>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive compares <em>TestString</em> to the empty string.</li>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive Treats the <em>TestString</em> as a pathname and tests
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin whether or not it exists, and is a directory.</li>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive Treats the <em>TestString</em> as a pathname and tests
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin whether or not it exists, and is a regular file.</li>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Treats the <em>TestString</em> as a pathname and tests
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin whether or not it exists, and is a regular file with size greater
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive than zero.</li>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Treats the <em>TestString</em> as a pathname and tests
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin whether or not it exists, and is a symbolic link.</li>
4e3cdb85620921a8a120fe22edbccae708f4f34end <li>'<strong>-x</strong>' (has e<strong>x</strong>ecutable
4e3cdb85620921a8a120fe22edbccae708f4f34end permissions)<br />
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin whether or not it exists, and has executable permissions.
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin These permissions are determined according to
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin the underlying OS.</li>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive subrequest)<br />
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Checks whether or not <em>TestString</em> is a valid file,
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive accessible via all the server's currently-configured
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive access controls for that path. This uses an internal
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin subrequest to do the check, so use it with care -
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin it can impact your server's performance!</li>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive subrequest)<br />
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Checks whether or not <em>TestString</em> is a valid URL,
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive accessible via all the server's currently-configured
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive access controls for that path. This uses an internal
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin subrequest to do the check, so use it with care -
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin it can impact your server's performance!</li>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive All of these tests can
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive also be prefixed by an exclamation mark ('!') to
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive negate their meaning.
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <li>You can also set special flags for
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <strong><code>[</code><em>flags</em><code>]</code></strong>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin as the third argument to the <code>RewriteCond</code>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin directive, where <em>flags</em> is a comma-separated list of any of the
5a4ba75a85817ca324e4f054d56f42a6a14adc5dnd following flags:
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin This makes the test case-insensitive - differences
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin between 'A-Z' and 'a-z' are ignored, both in the
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive expanded <em>TestString</em> and the <em>CondPattern</em>.
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive This flag is effective only for comparisons between
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <em>TestString</em> and <em>CondPattern</em>. It has no
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive effect on filesystem and subrequest checks.</li>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Use this to combine rule conditions with a local OR
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive instead of the implicit AND. Typical example:
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfsliveRewriteCond %{REMOTE_HOST} ^host1.* [OR]
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfsliveRewriteCond %{REMOTE_HOST} ^host2.* [OR]
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfsliveRewriteCond %{REMOTE_HOST} ^host3.*
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfsliveRewriteRule ...some special stuff for any of these hosts...
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Without this flag you would have to write the condition/rule
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin pair three times.
b65a184929c97d0b0e4d3bad42648e0e9ce1b8ferpluem If a HTTP header is used in the condition, this flag prevents
b65a184929c97d0b0e4d3bad42648e0e9ce1b8ferpluem this header from being added to the Vary header of the response. <br />
b65a184929c97d0b0e4d3bad42648e0e9ce1b8ferpluem Using this flag might break proper caching of the response if
b65a184929c97d0b0e4d3bad42648e0e9ce1b8ferpluem the representation of this response varies on the value of this header.
b65a184929c97d0b0e4d3bad42648e0e9ce1b8ferpluem So this flag should be only used if the meaning of the Vary header
b65a184929c97d0b0e4d3bad42648e0e9ce1b8ferpluem is well understood.
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p>To rewrite the Homepage of a site according to the
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive ``<code>User-Agent:</code>'' header of the request, you can
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive use the following: </p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfsliveRewriteCond %{HTTP_USER_AGENT} ^Mozilla.*
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfsliveRewriteRule ^/$ /homepage.max.html [L]
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfsliveRewriteCond %{HTTP_USER_AGENT} ^Lynx.*
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfsliveRewriteRule ^/$ /homepage.min.html [L]
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfsliveRewriteRule ^/$ /homepage.std.html [L]
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <p>Explanation: If you use a browser which identifies itself
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin as 'Mozilla' (including Netscape Navigator, Mozilla etc), then you
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin get the max homepage (which could include frames, or other special
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin If you use the Lynx browser (which is terminal-based), then
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin you get the min homepage (which could be a version designed for
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin easy, text-only browsing).
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin If neither of these conditions apply (you use any other browser,
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin or your browser identifies itself as something non-standard), you get
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin the std (standard) homepage.</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive</directivesynopsis>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<directivesynopsis>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<description>Defines rules for the rewriting engine</description>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<syntax>RewriteRule
96147932f199be4ad038778e702c13a2f79051c0slive <em>Pattern</em> <em>Substitution</em> [<em>flags</em>]</syntax>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<contextlist><context>server config</context><context>virtual host</context>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<context>directory</context><context>.htaccess</context></contextlist>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p>The <directive>RewriteRule</directive> directive is the real
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin rewriting workhorse. The directive can occur more than once,
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin with each instance defining a single rewrite rule. The
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin order in which these rules are defined is important - this is the order
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin in which they will be applied at run-time.</p>
630c456b6461158be6cc5c5483735e27b13b4ad5nd <p><a id="patterns" name="patterns"><em>Pattern</em></a> is
8c8c2e71c84babf0e8c4b35819c7c5b3be014cfenoodl expression</a>. On the first RewriteRule it is applied to the
8c8c2e71c84babf0e8c4b35819c7c5b3be014cfenoodl <a href="/directive-dict.html#Syntax">URL-path</a> of the request;
8c8c2e71c84babf0e8c4b35819c7c5b3be014cfenoodl subsequent patterns are applied to the output of the last matched
8c8c2e71c84babf0e8c4b35819c7c5b3be014cfenoodl RewriteRule.</p>
96147932f199be4ad038778e702c13a2f79051c0slive <p>The <em>Pattern</em> will initially be matched against the part of the
96147932f199be4ad038778e702c13a2f79051c0slive URL after the hostname and port, and before the query string. If you wish
96147932f199be4ad038778e702c13a2f79051c0slive to match against the hostname, port, or query string, use a
96147932f199be4ad038778e702c13a2f79051c0slive <directive module="mod_rewrite">RewriteCond</directive> with the
96147932f199be4ad038778e702c13a2f79051c0slive <code>%{HTTP_HOST}</code>, <code>%{SERVER_PORT}</code>, or
96147932f199be4ad038778e702c13a2f79051c0slive <code>%{QUERY_STRING}</code> variables respectively.</p>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <p>Some hints on the syntax of <glossary ref="regex">regular
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <strong><code>[</code></strong>chars<strong><code>]</code></strong> Character class: Any character of the class ``chars''
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <strong><code>[^</code></strong>chars<strong><code>]</code></strong> Character class: Not a character of the class ``chars''
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive text1<strong><code>|</code></strong>text2 Alternative: text1 or text2
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <strong><code>?</code></strong> 0 or 1 occurrences of the preceding text
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <strong><code>*</code></strong> 0 or N occurrences of the preceding text (N > 0)
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <strong><code>+</code></strong> 1 or N occurrences of the preceding text (N > 1)
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <strong><code>(</code></strong>text<strong><code>)</code></strong> Grouping of text
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin (used either to set the borders of an alternative as above, or
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin to make backreferences, where the <strong>N</strong>th group can
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin be referred to on the RHS of a RewriteRule as <code>$</code><strong>N</strong>)
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <strong><code>\</code></strong>char escape the given char
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin (for instance, to specify the chars "<code>.[]()</code>" <em>etc.</em>)
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <p>For more information about regular expressions, have a look at the
630c456b6461158be6cc5c5483735e27b13b4ad5nd perl regular expression manpage ("<a
630c456b6461158be6cc5c5483735e27b13b4ad5nd perlre</a>"). If you are interested in more detailed
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive information about regular expressions and their variants
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin (POSIX regex etc.) the following book is dedicated to this topic:</p>
edc8d9e0cce625a77afd1ff87a8f955694a973e2rbowen <em>Mastering Regular Expressions, 2nd Edition</em><br />
edc8d9e0cce625a77afd1ff87a8f955694a973e2rbowen O'Reilly & Associates, Inc. 2002<br />
edc8d9e0cce625a77afd1ff87a8f955694a973e2rbowen ISBN 0-596-00289-0<br />
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <p>In mod_rewrite, the NOT character
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin ('<code>!</code>') is also available as a possible pattern
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin prefix. This enables you to negate a pattern; to say, for instance:
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive ``<em>if the current URL does <strong>NOT</strong> match this
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive pattern</em>''. This can be used for exceptional cases, where
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive it is easier to match the negative pattern, or as a last
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive default rule.</p>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirinWhen using the NOT character to negate a pattern, you cannot include
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoiringrouped wildcard parts in that pattern. This is because, when the
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirinpattern does NOT match (ie, the negation matches), there are no
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirincontents for the groups. Thus, if negated patterns are used, you
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirincannot use <code>$N</code> in the substitution string!
96147932f199be4ad038778e702c13a2f79051c0slive <p>The <a id="rhs" name="rhs"><em>Substitution</em></a> of a
96147932f199be4ad038778e702c13a2f79051c0slive rewrite rule is the string that replaces the original URL-path that
96147932f199be4ad038778e702c13a2f79051c0slive was matched by <em>Pattern</em>. The <em>Substitution</em> may
96147932f199be4ad038778e702c13a2f79051c0slive <dd>Designates the location on the file-system of the resource
96147932f199be4ad038778e702c13a2f79051c0slive to be delivered to the client.</dd>
96147932f199be4ad038778e702c13a2f79051c0slive module="core">DocumentRoot</directive>-relative path to the
96147932f199be4ad038778e702c13a2f79051c0slive resource to be served. Note that <module>mod_rewrite</module>
96147932f199be4ad038778e702c13a2f79051c0slive tries to guess whether you have specified a file-system path
45309cf90ecc60d20e1ac810881e7b149fbe4e35noodl or a URL-path by checking to see if the first segment of the
96147932f199be4ad038778e702c13a2f79051c0slive path exists at the root of the file-system. For example, if
96147932f199be4ad038778e702c13a2f79051c0slive <code>/www/file.html</code>, then this will be treated as a
96147932f199be4ad038778e702c13a2f79051c0slive URL-path <em>unless</em> a directory named <code>www</code>
96147932f199be4ad038778e702c13a2f79051c0slive exists at the root or your file-system, in which case it will
96147932f199be4ad038778e702c13a2f79051c0slive be treated as a file-system path. If you wish other
96147932f199be4ad038778e702c13a2f79051c0slive URL-mapping directives (such as <directive
96147932f199be4ad038778e702c13a2f79051c0slive module="mod_alias">Alias</directive>) to be applied to the
96147932f199be4ad038778e702c13a2f79051c0slive described below.</dd>
96147932f199be4ad038778e702c13a2f79051c0slive <dd>If an absolute URL is specified,
96147932f199be4ad038778e702c13a2f79051c0slive <module>mod_rewrite</module> checks to see whether the
96147932f199be4ad038778e702c13a2f79051c0slive hostname matches the current host. If it does, the scheme and
96147932f199be4ad038778e702c13a2f79051c0slive hostname are stripped out and the resulting path is treated as
96147932f199be4ad038778e702c13a2f79051c0slive a URL-path. Otherwise, an external redirect is performed for
96147932f199be4ad038778e702c13a2f79051c0slive the given URL. To force an external redirect back to the
96147932f199be4ad038778e702c13a2f79051c0slive current host, see the <code>[R]</code> flag below.</dd>
96147932f199be4ad038778e702c13a2f79051c0slive <dd>A dash indicates that no substitution should be performed
96147932f199be4ad038778e702c13a2f79051c0slive (the existing path is passed through untouched). This is used
96147932f199be4ad038778e702c13a2f79051c0slive when a flag (see below) needs to be applied without changing
96147932f199be4ad038778e702c13a2f79051c0slive the path.</dd>
96147932f199be4ad038778e702c13a2f79051c0slive <p>In addition to plain text, the <em>Substition</em> string can include</p>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <li>back-references (<code>$N</code>) to the RewriteRule
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive pattern</li>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <li>back-references (<code>%N</code>) to the last matched
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive RewriteCond pattern</li>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <li>server-variables as in rule condition test-strings
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <p>Back-references are identifiers of the form
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive by the contents of the <strong>N</strong>th group of the
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive matched <em>Pattern</em>. The server-variables are the same
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive as for the <em>TestString</em> of a <code>RewriteCond</code>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive directive. The mapping-functions come from the
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <code>RewriteMap</code> directive and are explained there.
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin These three types of variables are expanded in the order above.</p>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <p>As already mentioned, all rewrite rules are
4bf4c38816cd24dab6fee4884ee98b58011cb6a5noirin applied to the <em>Substitution</em> (in the order in which
4bf4c38816cd24dab6fee4884ee98b58011cb6a5noirin they are defined
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin in the config file). The URL is <strong>completely
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive replaced</strong> by the <em>Substitution</em> and the
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin rewriting process continues until all rules have been applied,
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin or it is explicitly terminated by a
96147932f199be4ad038778e702c13a2f79051c0slive <p>By default, the query string is passed through unchanged. You
96147932f199be4ad038778e702c13a2f79051c0slive can, however, create URLs in the substitution string containing
96147932f199be4ad038778e702c13a2f79051c0slive a query string part. Simply use a question mark inside the
96147932f199be4ad038778e702c13a2f79051c0slive substitution string to indicate that the following text should
96147932f199be4ad038778e702c13a2f79051c0slive be re-injected into the query string. When you want to erase an
96147932f199be4ad038778e702c13a2f79051c0slive existing query string, end the substitution string with just a
96147932f199be4ad038778e702c13a2f79051c0slive question mark. To combine new and old query strings, use the
21f4ac5ab80abe4cbe90ae0f340c29053556c52drbowen <p>Additionally you can set special <a name="rewriteflags"
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin appending <strong><code>[</code><em>flags</em><code>]</code></strong>
96147932f199be4ad038778e702c13a2f79051c0slive directive. <em>Flags</em> is a comma-separated list, surround by square
96147932f199be4ad038778e702c13a2f79051c0slive brackets, of any of the following flags: </p>
5ff68527ed4cfc34ba93eb201b79fc3363ee66e4niq so backreferences will be unescaped at the time they are applied.
5ff68527ed4cfc34ba93eb201b79fc3363ee66e4niq Using the B flag, non-alphanumeric characters in backreferences
5ff68527ed4cfc34ba93eb201b79fc3363ee66e4niq will be escaped. For example, consider the rule:</p>
68e9d372e2a31a4b2575b2db3ec980dc9a4ea325noodl <pre><code> RewriteRule ^(.*)$ index.php?show=$1 </code></pre>
e68b66d35f349258a8221a78f236e7b92f828c29noodl <p>This will map <code>/C++</code> to <code>index.php?show=/C++</code>.
e68b66d35f349258a8221a78f236e7b92f828c29noodl <code>index.php?show=/C++</code>, because the <code>%2b</code>
5ff68527ed4cfc34ba93eb201b79fc3363ee66e4niq has been unescaped. With the B flag, it will instead map to
5ff68527ed4cfc34ba93eb201b79fc3363ee66e4niq <p>This escaping is particularly necessary in a proxy situation,
5ff68527ed4cfc34ba93eb201b79fc3363ee66e4niq when the backend may break if presented with an unescaped URL.</p>
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen This flag chains the current rule with the next rule
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen (which itself can be chained with the following rule,
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin and so on). This has the following effect: if a rule
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin matches, then processing continues as usual -
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen the flag has no effect. If the rule does
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen <strong>not</strong> match, then all following chained
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin rules are skipped. For instance, it can be used to remove the
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin ``<code>.www</code>'' part, inside a per-directory rule set,
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen when you let an external redirect happen (where the
5ff68527ed4cfc34ba93eb201b79fc3363ee66e4niq <dt>'<code>cookie|CO=</code><em>NAME</em>:<em>VAL</em>:<em>domain</em>[:<em>lifetime</em>[:<em>path</em>]]'
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin This sets a cookie in the client's browser. The cookie's name
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen <em>VAL</em>. The <em>domain</em> field is the domain of the
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin cookie, such as '.apache.org', the optional <em>lifetime</em>
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen is the lifetime of the cookie in minutes, and the optional
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin This forces an environment variable named <em>VAR</em> to
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen be set to the value <em>VAL</em>, where <em>VAL</em> can
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <code>%N</code>) which will be expanded. You can use this
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin flag more than once, to set more than one variable. The
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin variables can later be dereferenced in many situations, most commonly
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin from within XSSI (via <code><!--#echo
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin var="VAR"--></code>) or CGI (<code>$ENV{'VAR'}</code>).
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin You can also dereference the variable in a later RewriteCond pattern, using
8a571abb6573d916da05fc8b9f04fd944ad45803slive information from URLs, while maintaining a record of that information.</dd>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin This forces the current URL to be forbidden - it immediately
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin sends back a HTTP response of 403 (FORBIDDEN).
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Use this flag in conjunction with
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive appropriate RewriteConds to conditionally block some
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin This forces the current URL to be gone - it
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive immediately sends back a HTTP response of 410 (GONE). Use
8a571abb6573d916da05fc8b9f04fd944ad45803slive this flag to mark pages which no longer exist as gone.</dd>
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen Force the Content-handler of the target file to be
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen <em>Content-handler</em>. For instance, this can be used to
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <directive module="mod_alias">ScriptAlias</directive>,
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin which internally forces all files
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen inside the mapped directory to have a handler of
8ed0917f332087770872e032b248b2e1e689df3bslive here and don't apply any more rewrite rules. This corresponds
8ed0917f332087770872e032b248b2e1e689df3bslive <code>break</code> command in C. Use this flag to prevent the
8ed0917f332087770872e032b248b2e1e689df3bslive currently rewritten URL from being rewritten further by
8ed0917f332087770872e032b248b2e1e689df3bslive following rules. Remember, however, that if the
8ed0917f332087770872e032b248b2e1e689df3bslive <directive>RewriteRule</directive> generates an internal
8ed0917f332087770872e032b248b2e1e689df3bslive redirect (which frequently occurs when rewriting in a
8ed0917f332087770872e032b248b2e1e689df3bslive per-directory context), this will reinject the request and
8ed0917f332087770872e032b248b2e1e689df3bslive will cause processing to be repeated starting from the first
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Re-run the rewriting process (starting again with the
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin first rewriting rule). This time, the URL to match is no longer
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin the original URL, but rather the URL returned by the last rewriting rule.
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive This corresponds to the Perl <code>next</code> command or
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin this flag to restart the rewriting process -
8a571abb6573d916da05fc8b9f04fd944ad45803slive to immediately go to the top of the loop.
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <strong>Be careful not to create an infinite
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin ignoring difference between 'A-Z' and
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen 'a-z' when <em>Pattern</em> is matched against the current
8a571abb6573d916da05fc8b9f04fd944ad45803slive (no URI escaping of
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin This flag prevents mod_rewrite from applying the usual URI
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen escaping rules to the result of a rewrite. Ordinarily,
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen special characters (such as '%', '$', ';', and so on)
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen will be escaped into their hexcode equivalents ('%25',
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen '%24', and '%3B', respectively); this flag prevents this
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin from happening. This allows percent symbols to appear in
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen the output, as in
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen RewriteRule /foo/(.*) /bar?arg=P1\%3d$1 [R,NE]
8a571abb6573d916da05fc8b9f04fd944ad45803slive (not for internal
8a571abb6573d916da05fc8b9f04fd944ad45803slive <p>This flag forces the rewriting engine to skip a
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive rewriting rule if the current request is an internal
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive sub-request. For instance, sub-requests occur internally
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin in Apache when <module>mod_include</module> tries to find out
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive information about possible directory default files
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin (<code>index.xxx</code> files). On sub-requests it is not
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin always useful, and can even cause errors, if
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive the complete set of rules are applied. Use this flag to
8a571abb6573d916da05fc8b9f04fd944ad45803slive exclude some rules.</p>
8a571abb6573d916da05fc8b9f04fd944ad45803slive <p>To decide whether or not to use this rule: if you
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin prefix URLs with CGI-scripts, to force them to be
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin processed by the CGI-script, it's likely that you
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin will run into problems (or significant overhead) on
8a571abb6573d916da05fc8b9f04fd944ad45803slive sub-requests. In these cases, use this flag.</p>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin This flag forces the substitution part to be internally
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin sent as a proxy request and immediately (rewrite
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin processing stops here) put through the <a
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin href="mod_proxy.html">proxy module</a>. You must make
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen sure that the substitution string is a valid URI
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin (typically starting with
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin handled by the Apache proxy module. If not, you will get an
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen error from the proxy module. Use this flag to achieve a
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen more powerful implementation of the <a
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen href="mod_proxy.html#proxypass">ProxyPass</a> directive,
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin to map remote content into the namespace of the local
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <p>Note: <module>mod_proxy</module> must be enabled in order
9b82bd7c7f2083318e7856831dede324534308bcrbowen to use this flag.</p>
8a571abb6573d916da05fc8b9f04fd944ad45803slive (pass through to next
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin This flag forces the rewrite engine to set the
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <code>request_rec</code> structure to the value of the
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <code>filename</code> field. This flag is just a hack to
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin enable post-processing of the output of
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin various URI-to-filename translators. For example, to rewrite
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive RewriteRule ^/abc(.*) /def$1 [PT]<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive Alias /def /ghi
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <code>filename=/def/...</code> as a full API-compliant
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive URI-to-filename translator should do. Then
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin URI-to-filename transition, which will fail.
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <p>Note: <strong>You must use this flag if you want to
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin mix directives from different modules which allow
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive URL-to-filename translators</strong>. The typical example
b5407b0669a6a7175c84859e727d133399e4fa51slive <p>The <code>PT</code> flag implies the <code>L</code> flag:
b5407b0669a6a7175c84859e727d133399e4fa51slive rewriting will be stopped in order to pass the request to
b5407b0669a6a7175c84859e727d133399e4fa51slive the next phase of processing.</p>
8a571abb6573d916da05fc8b9f04fd944ad45803slive (query string
4bf4c38816cd24dab6fee4884ee98b58011cb6a5noirin This flag forces the rewrite engine to append a query
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin string part of the substitution string to the existing string,
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen instead of replacing it. Use this when you want to add more
8a571abb6573d916da05fc8b9f04fd944ad45803slive data to the query string via a rewrite rule.</dd>
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen <code>http://thishost[:thisport]/</code> (which makes the
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen new URL a URI) to force a external redirection. If no
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <em>code</em> is given, a HTTP response of 302 (MOVED
8a571abb6573d916da05fc8b9f04fd944ad45803slive TEMPORARILY) will be returned. If you want to use other
8a571abb6573d916da05fc8b9f04fd944ad45803slive response codes, simply specify the appropriate number or use
8a571abb6573d916da05fc8b9f04fd944ad45803slive one of the following symbolic names: <code>temp</code>
8a571abb6573d916da05fc8b9f04fd944ad45803slive <code>seeother</code>. Use this for rules to canonicalize
8a571abb6573d916da05fc8b9f04fd944ad45803slive the URL and return it to the client - to translate
8a571abb6573d916da05fc8b9f04fd944ad45803slive ``<code>/~</code>'' into ``<code>/u/</code>'', or to always
8a571abb6573d916da05fc8b9f04fd944ad45803slive append a slash to <code>/u/</code><em>user</em>, etc.<br />
8a571abb6573d916da05fc8b9f04fd944ad45803slive <strong>Note:</strong> When you use this flag, make sure
8a571abb6573d916da05fc8b9f04fd944ad45803slive that the substitution field is a valid URL! Otherwise, you
8a571abb6573d916da05fc8b9f04fd944ad45803slive will be redirecting to an invalid location. Remember that
8a571abb6573d916da05fc8b9f04fd944ad45803slive this flag on its own will only prepend
8a571abb6573d916da05fc8b9f04fd944ad45803slive <code>http://thishost[:thisport]/</code> to the URL, and
8a571abb6573d916da05fc8b9f04fd944ad45803slive rewriting will continue. Usually, you will want to stop
8a571abb6573d916da05fc8b9f04fd944ad45803slive rewriting at this point, and redirect immediately. To stop
8a571abb6573d916da05fc8b9f04fd944ad45803slive rewriting, you should add the 'L' flag.</p>
758cbf6f938a9e5b39422509d1e39b7078c1a1dcslive <p>While this is typically used for redirects, any valid status
758cbf6f938a9e5b39422509d1e39b7078c1a1dcslive code can be given here. If the status code is outside the redirect
758cbf6f938a9e5b39422509d1e39b7078c1a1dcslive range (300-399), then the <em>Substitution</em> string is dropped
758cbf6f938a9e5b39422509d1e39b7078c1a1dcslive and rewriting is stopped as if the <code>L</code> flag was
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin This flag forces the rewriting engine to skip the next
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive matches. Use this to make pseudo if-then-else constructs:
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive The last rule of the then-clause becomes
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <code>skip=N</code>, where N is the number of rules in the
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive else-clause. (This is <strong>not</strong> the same as the
8a571abb6573d916da05fc8b9f04fd944ad45803slive 'chain|C' flag!)</dd>
c14037646789087319802aaada2e8534ccab0158slive Force the <glossary>MIME-type</glossary> of the target file to be
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin set up the content-type based on some conditions.
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen For example, the following snippet allows <code>.php</code> files to
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen be <em>displayed</em> by <code>mod_php</code> if they are called with
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen RewriteRule ^(.+\.php)s$ $1 [T=application/x-httpd-php-source]
de68ca33425122cf4a880859013e08e84f8143a5covener<p> When the substitution string begins with a string
de68ca33425122cf4a880859013e08e84f8143a5covenerresembling "/~user" (via explicit text or backreferences), mod_rewrite performs
de68ca33425122cf4a880859013e08e84f8143a5covenerhome directory expansion independent of the presence or configuration
de68ca33425122cf4a880859013e08e84f8143a5covener<p> This expansion does not occur when the <em>PT</em>
de68ca33425122cf4a880859013e08e84f8143a5covenerflag is used on the <directive module="mod_rewrite">RewriteRule</directive>
de68ca33425122cf4a880859013e08e84f8143a5covenerdirective.</p>
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslivehref="/howto/htaccess.html">.htaccess</a> files. To enable the
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcsliverewrite engine for these files you need to set
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslive"<code>Options FollowSymLinks</code>" must be enabled. If your
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcsliveadministrator has disabled override of <code>FollowSymLinks</code> for
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslivea user's directory, then you cannot use the rewrite engine. This
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcsliverestriction is required for security reasons.</p>
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslive<p>When using the rewrite engine in <code>.htaccess</code> files the
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfsliveper-directory prefix (which always is the same for a specific
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirindirectory) is automatically <em>removed</em> for the pattern matching
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfsliveand automatically <em>added</em> after the substitution has been
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslivedone. This feature is essential for many sorts of rewriting; without
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslivethis, you would always have to match the parent directory, which is
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslivenot always possible. There is one exception: If a substitution string
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslivestarts with <code>http://</code>, then the directory prefix will
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslive<strong>not</strong> be added, and an external redirect (or proxy
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslivethroughput, if using flag <strong>P</strong>) is forced. See the
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslive<directive module="mod_rewrite">RewriteBase</directive> directive for
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslivemore information.</p>
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslive<p>The rewrite engine may also be used in <directive type="section"
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslivemodule="core">Directory</directive> sections with the same
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcsliveprefix-matching rules as would be applied to <code>.htaccess</code>
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslivefiles. It is usually simpler, however, to avoid the prefix substitution
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslivecomplication by putting the rewrite rules in the main server or
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslivevirtual host context, rather than in a <directive type="section"
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslive<p>Although rewrite rules are syntactically permitted in <directive
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcslivetype="section" module="core">Location</directive> sections, this
e9d3697fa9387adc0cc9a61b0c3ca75edfb83abcsliveshould never be necessary and is unsupported.</p>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <p>Here are all possible substitution combinations and their
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive meanings:</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive for request ``<code>GET
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<strong>Given Rule</strong> <strong>Resulting Substitution</strong>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive---------------------------------------------- ----------------------------------
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin^/somepath(.*) otherpath$1 invalid, not supported
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin^/somepath(.*) otherpath$1 [R] invalid, not supported
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin^/somepath(.*) otherpath$1 [P] invalid, not supported
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive---------------------------------------------- ----------------------------------
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive^/somepath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive via external redirection
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin^/somepath(.*) /otherpath$1 [P] doesn't make sense, not supported
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive---------------------------------------------- ----------------------------------
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive^/somepath(.*) http://thishost/otherpath$1 /otherpath/pathinfo
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive^/somepath(.*) http://thishost/otherpath$1 [R] http://thishost/otherpath/pathinfo
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive via external redirection
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin^/somepath(.*) http://thishost/otherpath$1 [P] doesn't make sense, not supported
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive---------------------------------------------- ----------------------------------
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive^/somepath(.*) http://otherhost/otherpath$1 http://otherhost/otherpath/pathinfo
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive via external redirection
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive^/somepath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfo
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive via external redirection
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive (the [R] flag is redundant)
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive^/somepath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfo
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive via internal proxy
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin (<code>/physical/path/to/somepath/.htacccess</code>, with
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive for request ``<code>GET
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive<strong>Given Rule</strong> <strong>Resulting Substitution</strong>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive---------------------------------------------- ----------------------------------
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive^localpath(.*) otherpath$1 /somepath/otherpath/pathinfo
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive^localpath(.*) otherpath$1 [R] http://thishost/somepath/otherpath/pathinfo
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive via external redirection
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin^localpath(.*) otherpath$1 [P] doesn't make sense, not supported
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive---------------------------------------------- ----------------------------------
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive^localpath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive via external redirection
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin^localpath(.*) /otherpath$1 [P] doesn't make sense, not supported
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive---------------------------------------------- ----------------------------------
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive^localpath(.*) http://thishost/otherpath$1 /otherpath/pathinfo
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive^localpath(.*) http://thishost/otherpath$1 [R] http://thishost/otherpath/pathinfo
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive via external redirection
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin^localpath(.*) http://thishost/otherpath$1 [P] doesn't make sense, not supported
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive---------------------------------------------- ----------------------------------
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive^localpath(.*) http://otherhost/otherpath$1 http://otherhost/otherpath/pathinfo
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive via external redirection
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive^localpath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfo
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive via external redirection
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive (the [R] flag is redundant)
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive^localpath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfo
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive via internal proxy
013e1ddd21f2142a369c9a9a0eeb6c6a0bc3fcf3patrikj </directivesynopsis>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive</modulesynopsis>