mod_rewrite.xml revision e3f22cc532d5d8b11560f70e994d6ac281b35b50
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>
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim <p>The <module>mod_rewrite</module> module uses a rule-based rewriting
eda63965b78ffeb9384c429c53f4eb5d22c2ca2arbowen engine, based on a PCRE regular-expression parser, to rewrite requested URLs on
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim the fly. By default, <module>mod_rewrite</module> maps a URL to a filesystem
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin path. However, it can also be used to redirect one URL to another URL, or
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin to invoke an internal proxy fetch.</p>
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim <p><module>mod_rewrite</module> provides a flexible and powerful way to
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim manipulate URLs using an unlimited number of rules. Each rule can have an
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin unlimited number of attached rule conditions, to allow you to rewrite URL
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim based on server variables, environment variables, HTTP headers, or time
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin stamps.</p>
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin <p><module>mod_rewrite</module> operates on the full URL path, including the
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim path-info section. A rewrite rule can be invoked in
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim <code>httpd.conf</code> or in <code>.htaccess</code>. The path generated
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim by a rewrite rule can include a query string, or can lead to internal
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim sub-processing, external request redirection, or internal proxy
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin throughput.</p>
f0a393c5c2d7de58f447855369ad2fbfa254e544rbowen <p>Further details, discussion, and examples, are provided in the
f0a393c5c2d7de58f447855369ad2fbfa254e544rbowen <a href="/rewrite/">detailed mod_rewrite documentation</a>.</p>
bc36e90829b1ee123307a2339519265139a88173sf <p><module>mod_rewrite</module> offers detailed logging of its actions
bc36e90829b1ee123307a2339519265139a88173sf at the <code>trace1</code> to <code>trace8</code> log levels. The
bc36e90829b1ee123307a2339519265139a88173sf log level can be set specifically for <module>mod_rewrite</module>
bc36e90829b1ee123307a2339519265139a88173sf using the <directive module="core">LogLevel</directive> directive: Up to
bc36e90829b1ee123307a2339519265139a88173sf level <code>debug</code>, no actions are logged, while <code>trace8</code>
bc36e90829b1ee123307a2339519265139a88173sf means that practically all actions are logged.</p>
bc36e90829b1ee123307a2339519265139a88173sf Using a high trace log level for <module>mod_rewrite</module>
bc36e90829b1ee123307a2339519265139a88173sf will slow down your Apache HTTP Server dramatically! Use a log
1f0a28764a0520e43ce3a9130e56236fd67cd568igalic level higher than <code>trace2</code> only for debugging!
4927aa0c58523071e62d47580cec3b1fb1100ae2rbowen LogLevel alert rewrite:trace3
3a257106808eabaefbb483bdc6273e7af062ead8humbedooh </highlight>
bc36e90829b1ee123307a2339519265139a88173sf </example>
9b3696c7ad70387ecd46e0f061b99d381dc392f9rbowen <p>Those familiar with earlier versions of
9b3696c7ad70387ecd46e0f061b99d381dc392f9rbowen <module>mod_rewrite</module> will no doubt be looking for the
9b3696c7ad70387ecd46e0f061b99d381dc392f9rbowen <code>RewriteLog</code> and <code>RewriteLogLevel</code>
9b3696c7ad70387ecd46e0f061b99d381dc392f9rbowen directives. This functionality has been completely replaced by the
9b3696c7ad70387ecd46e0f061b99d381dc392f9rbowen new per-module logging configuration mentioned above.
9b3696c7ad70387ecd46e0f061b99d381dc392f9rbowen <p>To get just the <module>mod_rewrite</module>-specific log
9b3696c7ad70387ecd46e0f061b99d381dc392f9rbowen messages, pipe the log file through grep:</p>
9b3696c7ad70387ecd46e0f061b99d381dc392f9rbowen tail -f error_log|fgrep '[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>
add05d0fdfd18b515383629b1b58130ada068dffrbowen <p>Use this directive to disable rules in a particular contact,
add05d0fdfd18b515383629b1b58130ada068dffrbowen rather than commenting out all the <directive
add05d0fdfd18b515383629b1b58130ada068dffrbowen 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>
fc9f416faa11879811f17d6efadedbf81cfd52a1covener <p><directive>RewriteMap</directive> directives of the type <code>prg</code>
fc9f416faa11879811f17d6efadedbf81cfd52a1covener are not started during server initialization if they're defined in a
fc9f416faa11879811f17d6efadedbf81cfd52a1covener context that does not have <directive>RewriteEngine</directive> set to
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>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p>The <directive>RewriteOptions</directive> directive sets some
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive special options for the current per-server or per-directory
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor configuration. The <em>Option</em> string can currently
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin only be one of the following:</p>
1437d609a6e92c3f32dfdb0d63fce4fd2243fa0frbowen <p>This forces the current configuration to inherit the
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin configuration of the parent. In per-virtual-server context,
9ed9ba1fcf0a4a39f78f5f809c661bbd590b70eand this means that the maps, conditions and rules of the main
9ed9ba1fcf0a4a39f78f5f809c661bbd590b70eand server are inherited. In per-directory context this means
9ed9ba1fcf0a4a39f78f5f809c661bbd590b70eand that conditions and rules of the parent directory's
a4d04b8c74044c58bd4182028a1408d936c95951covener <directive type="section" module="core">Directory</directive>
a4d04b8c74044c58bd4182028a1408d936c95951covener sections are inherited. The inherited rules are virtually copied
a4d04b8c74044c58bd4182028a1408d936c95951covener to the section where this directive is being used. If used in
a4d04b8c74044c58bd4182028a1408d936c95951covener combination with local rules, the inherited rules are copied behind
a4d04b8c74044c58bd4182028a1408d936c95951covener the local rules. The position of this directive - below or above
a4d04b8c74044c58bd4182028a1408d936c95951covener of local rules - has no influence on this behavior. If local
a4d04b8c74044c58bd4182028a1408d936c95951covener rules forced the rewriting to stop, the inherited rules won't
1437d609a6e92c3f32dfdb0d63fce4fd2243fa0frbowen be processed.</p>
1437d609a6e92c3f32dfdb0d63fce4fd2243fa0frbowen Rules inherited from the parent scope are applied
1437d609a6e92c3f32dfdb0d63fce4fd2243fa0frbowen <strong>after</strong> rules specified in the child scope.
6f2fbf354b34981f398cf0313aa44702ea2a7066covener <p> Like <code>Inherit</code> above, but the rules from the parent scope
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim are applied <strong>before</strong> rules specified in the child scope.
6f2fbf354b34981f398cf0313aa44702ea2a7066covener Available in Apache HTTP Server 2.3.10 and later.</p>
46578aac029a8de1703b48f8050c56d3e9442e5eminfrin <p>By default, <module>mod_rewrite</module> will ignore URLs that map to a
46578aac029a8de1703b48f8050c56d3e9442e5eminfrin directory on disk but lack a trailing slash, in the expectation that
46578aac029a8de1703b48f8050c56d3e9442e5eminfrin the <module>mod_dir</module> module will issue the client with a redirect to
46578aac029a8de1703b48f8050c56d3e9442e5eminfrin the canonical URL with a trailing slash.</p>
46578aac029a8de1703b48f8050c56d3e9442e5eminfrin <p>When the <directive module="mod_dir">DirectorySlash</directive> directive
46578aac029a8de1703b48f8050c56d3e9442e5eminfrin is set to off, the <code>AllowNoSlash</code> option can be enabled to ensure
46578aac029a8de1703b48f8050c56d3e9442e5eminfrin that rewrite rules are no longer ignored. This option makes it possible to
46578aac029a8de1703b48f8050c56d3e9442e5eminfrin apply rewrite rules within .htaccess files that match the directory without
46578aac029a8de1703b48f8050c56d3e9442e5eminfrin a trailing slash, if so desired. Available in Apache HTTP Server 2.4.0 and
72709d60c290ddc1f60fe2c78ab67b7954e9230djorton <p>When <directive module="mod_rewrite">RewriteRule</directive>
72709d60c290ddc1f60fe2c78ab67b7954e9230djorton is used in <code>VirtualHost</code> or server context with
72709d60c290ddc1f60fe2c78ab67b7954e9230djorton version 2.2.22 or later of httpd, <module>mod_rewrite</module>
72709d60c290ddc1f60fe2c78ab67b7954e9230djorton will only process the rewrite rules if the request URI is a <a
ae382386f18506586972cdd63c09bb27a1685062nd href="directive-dict.html#Syntax">URL-path</a>. This avoids
72709d60c290ddc1f60fe2c78ab67b7954e9230djorton some security issues where particular rules could allow
72709d60c290ddc1f60fe2c78ab67b7954e9230djorton "surprising" pattern expansions (see <a
72709d60c290ddc1f60fe2c78ab67b7954e9230djorton href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-3368">CVE-2011-3368</a>
72709d60c290ddc1f60fe2c78ab67b7954e9230djorton href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-4317">CVE-2011-4317</a>).
72709d60c290ddc1f60fe2c78ab67b7954e9230djorton To lift the restriction on matching a URL-path, the
72709d60c290ddc1f60fe2c78ab67b7954e9230djorton <module>mod_rewrite</module> will apply the rule set to any
72709d60c290ddc1f60fe2c78ab67b7954e9230djorton request URI string, regardless of whether that string matches
72709d60c290ddc1f60fe2c78ab67b7954e9230djorton the URL-path grammar required by the HTTP specification.</p>
72709d60c290ddc1f60fe2c78ab67b7954e9230djorton <p>Enabling this option will make the server vulnerable to
72709d60c290ddc1f60fe2c78ab67b7954e9230djorton security issues if used with rewrite rules which are not
72709d60c290ddc1f60fe2c78ab67b7954e9230djorton carefully authored. It is <strong>strongly recommended</strong>
72709d60c290ddc1f60fe2c78ab67b7954e9230djorton that this option is not used. In particular, beware of input
72709d60c290ddc1f60fe2c78ab67b7954e9230djorton strings containing the '<code>@</code>' character which could
72709d60c290ddc1f60fe2c78ab67b7954e9230djorton change the interpretation of the transformed URI, as per the
72709d60c290ddc1f60fe2c78ab67b7954e9230djorton above CVE names.</p>
855d6aa9f641cd160ee4265824a3ad3d06231c76covener <p>With this option, the value of <directive module="mod_rewrite"
855d6aa9f641cd160ee4265824a3ad3d06231c76covener >RewriteBase</directive> is copied from where it's explicitly defined
855d6aa9f641cd160ee4265824a3ad3d06231c76covener into any sub-directory or sub-location that doesn't define its own
855d6aa9f641cd160ee4265824a3ad3d06231c76covener <directive module="mod_rewrite">RewriteBase</directive>. Available in
855d6aa9f641cd160ee4265824a3ad3d06231c76covener Apache HTTP Server 2.5 and later only.</p>
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>
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
7992de7f9e82ab86effe3dcc5279fb959f6c398dcovener if no <em>DefaultValue</em> was specified. Empty values
7992de7f9e82ab86effe3dcc5279fb959f6c398dcovener behave as if the key was absent, therefore it is not possible
7992de7f9e82ab86effe3dcc5279fb959f6c398dcovener to distinguish between empty-valued keys and absent keys.</p>
ee73c32ad65734a6514bcbd0ed6e20494e8a50bdrbowen <p>For example, you might define a
3a257106808eabaefbb483bdc6273e7af062ead8humbedooh </highlight>
ee73c32ad65734a6514bcbd0ed6e20494e8a50bdrbowen <p>You would then be able to use this map in a
8ac3ff7008df949c096f9cd8f769c7893594f61fnd RewriteRule ^/ex/(.*) ${examplemap:$1}
3a257106808eabaefbb483bdc6273e7af062ead8humbedooh </highlight>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <p>The following combinations for <em>MapType</em> and
790a477f6ce41161c4173c1e5080a1f569976a1erbowen <dd>A plain text file containing space-separated key-value
790a477f6ce41161c4173c1e5080a1f569976a1erbowen pairs, one per line. (<a href="/rewrite/rewritemap.html#txt">Details ...</a>)</dd>
790a477f6ce41161c4173c1e5080a1f569976a1erbowen <dd>Randomly selects an entry from a plain text file (<a href="/rewrite/rewritemap.html#rnd">Details ...</a>)</dd>
790a477f6ce41161c4173c1e5080a1f569976a1erbowen <dd>Looks up an entry in a dbm file containing name, value
0a3142725875ea286597e083547d34d98f8c1f2drbowen pairs. Hash is constructed from a plain text file format using
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim the <code><a href="/programs/httxt2dbm.html">httxt2dbm</a></code>
790a477f6ce41161c4173c1e5080a1f569976a1erbowen utility. (<a href="/rewrite/rewritemap.html#dbm">Details ...</a>)</dd>
dc585e0df783dd91b8121ea1cfa743cea2ac12fdcovener <dd>One of the four available internal functions provided by
dc585e0df783dd91b8121ea1cfa743cea2ac12fdcovener <code>RewriteMap</code>: toupper, tolower, escape or
dc585e0df783dd91b8121ea1cfa743cea2ac12fdcovener unescape. (<a href="/rewrite/rewritemap.html#int">Details ...</a>)</dd>
790a477f6ce41161c4173c1e5080a1f569976a1erbowen <dd>Calls an external program or script to process the
790a477f6ce41161c4173c1e5080a1f569976a1erbowen rewriting. (<a href="/rewrite/rewritemap.html#prg">Details ...</a>)</dd>
790a477f6ce41161c4173c1e5080a1f569976a1erbowen <dd>A SQL SELECT statement to be performed to look up the
790a477f6ce41161c4173c1e5080a1f569976a1erbowen rewrite target. (<a href="/rewrite/rewritemap.html#dbd">Details ...</a>)</dd>
0a3142725875ea286597e083547d34d98f8c1f2drbowen <p>Further details, and numerous examples, may be found in the <a
0a3142725875ea286597e083547d34d98f8c1f2drbowen href="/rewrite/rewritemap.html">RewriteMap HowTo</a></p>
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>
825119afb439c424c7c124efc0d6d6b197a1f356covener <p>The <directive>RewriteBase</directive> directive specifies the
825119afb439c424c7c124efc0d6d6b197a1f356covener URL prefix to be used for per-directory (htaccess)
825119afb439c424c7c124efc0d6d6b197a1f356covener <directive>RewriteRule</directive> directives that substitute a relative
825119afb439c424c7c124efc0d6d6b197a1f356covener <p> This directive is <em>required</em> when you use a relative path
825119afb439c424c7c124efc0d6d6b197a1f356covener in a substitution in per-directory (htaccess) context unless either
8a742f67b2f07505fc32e4f48f436509ea8f0320nilgun of the following conditions are true:</p>
825119afb439c424c7c124efc0d6d6b197a1f356covener <li> The original request, and the substitution, are underneath the
825119afb439c424c7c124efc0d6d6b197a1f356covener (as opposed to reachable by other means, such as
825119afb439c424c7c124efc0d6d6b197a1f356covener <directive module="mod_alias">Alias</directive>).</li>
825119afb439c424c7c124efc0d6d6b197a1f356covener <li> The <em>filesystem</em> path to the directory containing the
825119afb439c424c7c124efc0d6d6b197a1f356covener <directive>RewriteRule</directive>, suffixed by the relative
825119afb439c424c7c124efc0d6d6b197a1f356covener substitution is also valid as a URL path on the server
825119afb439c424c7c124efc0d6d6b197a1f356covener (this is rare).</li>
825119afb439c424c7c124efc0d6d6b197a1f356covener<p> In the example below, <directive>RewriteBase</directive> is necessary
825119afb439c424c7c124efc0d6d6b197a1f356covener to avoid rewriting to http://example.com/opt/myapp-1.2.3/welcome.html
825119afb439c424c7c124efc0d6d6b197a1f356covener since the resource was not relative to the document root. This
825119afb439c424c7c124efc0d6d6b197a1f356covener misconfiguration would normally cause the server to look for an "opt"
825119afb439c424c7c124efc0d6d6b197a1f356covener directory under the document root.</p>
3a257106808eabaefbb483bdc6273e7af062ead8humbedooh RewriteEngine On
3a257106808eabaefbb483bdc6273e7af062ead8humbedooh RewriteBase /myapp/
3a257106808eabaefbb483bdc6273e7af062ead8humbedooh RewriteRule ^index\.html$ welcome.html
825119afb439c424c7c124efc0d6d6b197a1f356covener</Directory>
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>
fa0f379e3845907d7c1087d885169e302239bdbbnd <p>The <directive>RewriteCond</directive> directive defines a
fa0f379e3845907d7c1087d885169e302239bdbbnd rule condition. One or more <directive>RewriteCond</directive>
fa0f379e3845907d7c1087d885169e302239bdbbnd can precede a <directive module="mod_rewrite">RewriteRule</directive>
fa0f379e3845907d7c1087d885169e302239bdbbnd directive. The following rule is then only used if both
fa0f379e3845907d7c1087d885169e302239bdbbnd the current state of the URI matches its pattern, <strong
fa0f379e3845907d7c1087d885169e302239bdbbnd 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>
b115299831a7b4bbec58a88d708d8536e1ecd50csf (0 <= N <= 9). $1 to $9 provide access to the grouped
fa0f379e3845907d7c1087d885169e302239bdbbnd parts (in parentheses) of the pattern, from the
b115299831a7b4bbec58a88d708d8536e1ecd50csf access to the whole string matched by that pattern.
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <strong>RewriteCond backreferences</strong>: These are
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin backreferences of the form <strong><code>%N</code></strong>
b115299831a7b4bbec58a88d708d8536e1ecd50csf (0 <= N <= 9). %1 to %9 provide access to the grouped
fa0f379e3845907d7c1087d885169e302239bdbbnd parts (again, in parentheses) of the pattern, from the last matched
b115299831a7b4bbec58a88d708d8536e1ecd50csf of conditions. %0 provides access to the whole string matched by
b115299831a7b4bbec58a88d708d8536e1ecd50csf that pattern.
fa0f379e3845907d7c1087d885169e302239bdbbnd RewriteMap</a> for more details.
fa0f379e3845907d7c1087d885169e302239bdbbnd <strong>Server-Variables</strong>: These are variables of
fa0f379e3845907d7c1087d885169e302239bdbbnd from the following list:
97a9a944b5887e91042b019776c41d5dd74557aferikabele <th>HTTP headers:</th> <th>connection & request:</th> <th></th>
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi HTTP_USER_AGENT<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive HTTP_REFERER<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive HTTP_COOKIE<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive HTTP_FORWARDED<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive HTTP_HOST<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive HTTP_PROXY_CONNECTION<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive HTTP_ACCEPT<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele REMOTE_ADDR<br />
a4bcadc43f29245972e9e8745a5114610065329ccovener CONN_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>
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi DOCUMENT_ROOT<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive SERVER_ADMIN<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive SERVER_NAME<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive SERVER_ADDR<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive SERVER_PORT<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive SERVER_PROTOCOL<br />
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive SERVER_SOFTWARE<br />
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 />
4203a35c28d7c60adb7e9ef3be87aad34951c79asf REQUEST_SCHEME<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd <p>These variables all
fa0f379e3845907d7c1087d885169e302239bdbbnd correspond to the similarly named HTTP
cea021a7fc2657b091df4d3b031c4254ec371dd7rbowen MIME-headers, C variables of the Apache HTTP Server or
fa0f379e3845907d7c1087d885169e302239bdbbnd Most are documented elsewhere in the Manual or in
6d39241b884dd91f791c438d7846c2acf47d94a8covener the CGI specification.</p>
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim <p>SERVER_NAME and SERVER_PORT depend on the values of
6d39241b884dd91f791c438d7846c2acf47d94a8covener <directive module="core">UseCanonicalName</directive> and
6d39241b884dd91f791c438d7846c2acf47d94a8covener <directive module="core">UseCanonicalPhysicalPort</directive>
6d39241b884dd91f791c438d7846c2acf47d94a8covener respectively.</p>
6d39241b884dd91f791c438d7846c2acf47d94a8covener <p>Those that are special to mod_rewrite include those below.</p>
fa0f379e3845907d7c1087d885169e302239bdbbnd <dd>Will contain the text "true" if the request
fa0f379e3845907d7c1087d885169e302239bdbbnd 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>
cea021a7fc2657b091df4d3b031c4254ec371dd7rbowen <dd>This is the version of the Apache httpd module API
fa0f379e3845907d7c1087d885169e302239bdbbnd (the internal interface between server and
fa0f379e3845907d7c1087d885169e302239bdbbnd module) in the current httpd build, as defined in
cea021a7fc2657b091df4d3b031c4254ec371dd7rbowen corresponds to the version of Apache httpd in use (in
cea021a7fc2657b091df4d3b031c4254ec371dd7rbowen the release version of Apache httpd 1.3.14, for
fa0f379e3845907d7c1087d885169e302239bdbbnd instance, it is 19990320:10), but is mainly of
fa0f379e3845907d7c1087d885169e302239bdbbnd interest to module authors.</dd>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <dd>The full HTTP request line sent by the
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive include any additional headers sent by the
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim browser. This value has not been unescaped
777c17c11c2b1638f191241364e034779851d186covener (decoded), unlike most other variables below.</dd>
cc4f6dc97c7a492e099fed60453743cd82148beacovener <dd>The path component of the requested URI,
cc4f6dc97c7a492e099fed60453743cd82148beacovener such as "/index.html". This notably excludes the
cc4f6dc97c7a492e099fed60453743cd82148beacovener query string which is available as as its own variable
fa0f379e3845907d7c1087d885169e302239bdbbnd <dd>The full local filesystem path to the file or
c0a201f9f0cda37f4e5829462c7e489f85bf327ccovener script matching the request, if this has already
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim been determined by the server at the time
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim such as when used in virtual host context, the same
7b9b6d4364d3a3676959ba353cd43c6f05295682covener value as <code>REQUEST_URI</code>. Depending on the value of
9153a696314d93c5dcdd2539d7d9ebf746ecd77dcovener <directive module="core">AcceptPathInfo</directive>, the
9153a696314d93c5dcdd2539d7d9ebf746ecd77dcovener server may have only used some leading components of the
7b9b6d4364d3a3676959ba353cd43c6f05295682covener <code>REQUEST_URI</code> to map the request to a file.
fa0f379e3845907d7c1087d885169e302239bdbbnd <dd>Will contain the text "on" if the connection is
fa0f379e3845907d7c1087d885169e302239bdbbnd can be safely used regardless of whether or not
ff165e24f20fdebbe3651ed6aee03d7e13299d35humbedooh <dd>Will contain the scheme of the request (usually
4203a35c28d7c60adb7e9ef3be87aad34951c79asf "http" or "https"). This value can be influenced with
a4bcadc43f29245972e9e8745a5114610065329ccovener <dd>The IP address of the remote host (see the
a4bcadc43f29245972e9e8745a5114610065329ccovener <dd>Since 2.4.8: The peer IP address of the connection (see the
491809c1661a323205c91df21e69225cc3d6e37bsf <p>If the <em>TestString</em> has the special value <code>expr</code>,
491809c1661a323205c91df21e69225cc3d6e37bsf <a href="/expr.html">ap_expr</a>. HTTP headers referenced in the
491809c1661a323205c91df21e69225cc3d6e37bsf expression will be added to the Vary header if the <code>novary</code>
491809c1661a323205c91df21e69225cc3d6e37bsf flag is not given.</p>
fa0f379e3845907d7c1087d885169e302239bdbbnd <p>The variables SCRIPT_FILENAME and REQUEST_FILENAME
fa0f379e3845907d7c1087d885169e302239bdbbnd contain the same value - the value of the
cea021a7fc2657b091df4d3b031c4254ec371dd7rbowen <code>request_rec</code> structure of the Apache HTTP Server.
fa0f379e3845907d7c1087d885169e302239bdbbnd The first name is the commonly known CGI variable name
fa0f379e3845907d7c1087d885169e302239bdbbnd while the second is the appropriate counterpart of
fa0f379e3845907d7c1087d885169e302239bdbbnd REQUEST_URI (which contains the value of the
fa0f379e3845907d7c1087d885169e302239bdbbnd <p>If a substitution occurred and the rewriting continues,
fa0f379e3845907d7c1087d885169e302239bdbbnd the value of both variables will be updated accordingly.</p>
fa0f379e3845907d7c1087d885169e302239bdbbnd <p>If used in per-server context (<em>i.e.</em>, before the
fa0f379e3845907d7c1087d885169e302239bdbbnd request is mapped to the filesystem) SCRIPT_FILENAME and
fa0f379e3845907d7c1087d885169e302239bdbbnd REQUEST_FILENAME cannot contain the full local filesystem
fa0f379e3845907d7c1087d885169e302239bdbbnd path since the path is unknown at this stage of processing.
fa0f379e3845907d7c1087d885169e302239bdbbnd Both variables will initially contain the value of REQUEST_URI
fa0f379e3845907d7c1087d885169e302239bdbbnd in that case. In order to obtain the full local filesystem
fa0f379e3845907d7c1087d885169e302239bdbbnd path of the request in per-server context, use an URL-based
a4d04b8c74044c58bd4182028a1408d936c95951covener look-ahead <code>%{LA-U:REQUEST_FILENAME}</code> to determine
fa0f379e3845907d7c1087d885169e302239bdbbnd <code>%{ENV:variable}</code>, where <em>variable</em> can be
fa0f379e3845907d7c1087d885169e302239bdbbnd any environment variable, is also available.
fa0f379e3845907d7c1087d885169e302239bdbbnd This is looked-up via internal
cea021a7fc2657b091df4d3b031c4254ec371dd7rbowen Apache httpd structures and (if not found there) via
cea021a7fc2657b091df4d3b031c4254ec371dd7rbowen <code>getenv()</code> from the Apache httpd server process.</li>
fa0f379e3845907d7c1087d885169e302239bdbbnd <code>%{SSL:variable}</code>, where <em>variable</em> is the
7748a5c411233f9e1f3df10ea5fffffa91e58824jorton name of an <a href="mod_ssl.html#envvars">SSL environment
fa0f379e3845907d7c1087d885169e302239bdbbnd variable</a>, can be used whether or not
fa0f379e3845907d7c1087d885169e302239bdbbnd <module>mod_ssl</module> is loaded, but will always expand to
fa0f379e3845907d7c1087d885169e302239bdbbnd the empty string if it is not. Example:
fa0f379e3845907d7c1087d885169e302239bdbbnd <code>%{HTTP:header}</code>, where <em>header</em> can be
fa0f379e3845907d7c1087d885169e302239bdbbnd any HTTP MIME-header name, can always be used to obtain the
fa0f379e3845907d7c1087d885169e302239bdbbnd value of a header sent in the HTTP request.
fa0f379e3845907d7c1087d885169e302239bdbbnd the value of the HTTP header
fa0f379e3845907d7c1087d885169e302239bdbbnd <p>If a HTTP header is used in a condition this header is added to
fa0f379e3845907d7c1087d885169e302239bdbbnd the Vary header of the response in case the condition evaluates to
fa0f379e3845907d7c1087d885169e302239bdbbnd to true for the request. It is <strong>not</strong> added if the
fa0f379e3845907d7c1087d885169e302239bdbbnd condition evaluates to false for the request. Adding the HTTP header
fa0f379e3845907d7c1087d885169e302239bdbbnd to the Vary header of the response is needed for proper caching.</p>
fa0f379e3845907d7c1087d885169e302239bdbbnd <p>It has to be kept in mind that conditions follow a short circuit
fa0f379e3845907d7c1087d885169e302239bdbbnd logic in the case of the '<strong><code>ornext|OR</code></strong>' flag
fa0f379e3845907d7c1087d885169e302239bdbbnd so that certain conditions might not be evaluated at all.</p></li>
025dc11c0fd8d6a7fdb5f0a46cc3a5fbab64b93drbowen <a id="LA-U" name="LA-U"><code>%{LA-U:variable}</code></a>
025dc11c0fd8d6a7fdb5f0a46cc3a5fbab64b93drbowen can be used for look-aheads which perform
fa0f379e3845907d7c1087d885169e302239bdbbnd an internal (URL-based) sub-request to determine the final
fa0f379e3845907d7c1087d885169e302239bdbbnd variable for rewriting which is not available at the current
fa0f379e3845907d7c1087d885169e302239bdbbnd stage, but will be set in a later phase.
fa0f379e3845907d7c1087d885169e302239bdbbnd <p>For instance, to rewrite according to the
fa0f379e3845907d7c1087d885169e302239bdbbnd per-server context (<code>httpd.conf</code> file) you must
fa0f379e3845907d7c1087d885169e302239bdbbnd variable is set by the authorization phases, which come
fa0f379e3845907d7c1087d885169e302239bdbbnd <em>after</em> the URL translation phase (during which mod_rewrite
fa0f379e3845907d7c1087d885169e302239bdbbnd operates).</p>
fa0f379e3845907d7c1087d885169e302239bdbbnd <p>On the other hand, because mod_rewrite implements
fa0f379e3845907d7c1087d885169e302239bdbbnd its per-directory context (<code>.htaccess</code> file) via
fa0f379e3845907d7c1087d885169e302239bdbbnd the Fixup phase of the API and because the authorization
fa0f379e3845907d7c1087d885169e302239bdbbnd <code>%{LA-F:variable}</code> can be used to perform an internal
fa0f379e3845907d7c1087d885169e302239bdbbnd (filename-based) sub-request, to determine the final value
fa0f379e3845907d7c1087d885169e302239bdbbnd of <em>variable</em>. Most of the time, this is the same as
fa0f379e3845907d7c1087d885169e302239bdbbnd LA-U above.</li>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin a regular expression which is applied to the
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <em>TestString</em> is first evaluated, before being matched against
88f586e767b7b224bdb1a178455668a2475cfc75rbowen <em>perl compatible regular expression</em>, but there is
88f586e767b7b224bdb1a178455668a2475cfc75rbowen additional syntax available to perform other useful tests against
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <li>You can prefix the pattern string with a
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive '<code>!</code>' character (exclamation mark) to specify a
88f586e767b7b224bdb1a178455668a2475cfc75rbowen You can perform lexicographical string comparisons:
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor <li>'<strong><CondPattern</strong>' (lexicographically
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi precedes)<br />
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Treats the <em>CondPattern</em> as a plain string and
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin compares it lexicographically to <em>TestString</em>. True if
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <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>
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen <li>'<strong><=CondPattern</strong>' (lexicographically
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen less than or equal to)<br />
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen Treats the <em>CondPattern</em> as a plain string and
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen compares it lexicographically to <em>TestString</em>. True
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen <em>CondPattern</em>, or is equal to <em>CondPattern</em>
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen (the two strings are equal, character for character).</li>
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen <li>'<strong>>=CondPattern</strong>' (lexicographically
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen greater than or equal to)<br />
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen Treats the <em>CondPattern</em> as a plain string and
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen compares it lexicographically to <em>TestString</em>. True
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen <em>CondPattern</em>, or is equal to <em>CondPattern</em>
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen (the two strings are equal, character for character).</li>
88f586e767b7b224bdb1a178455668a2475cfc75rbowen You can perform integer comparisons:
88f586e767b7b224bdb1a178455668a2475cfc75rbowen The <em>TestString</em> is treated as an integer, and is
88f586e767b7b224bdb1a178455668a2475cfc75rbowen numerically compared to the <em>CondPattern</em>. True if
88f586e767b7b224bdb1a178455668a2475cfc75rbowen the two are numerically equal.</li>
88f586e767b7b224bdb1a178455668a2475cfc75rbowen <strong>g</strong>reater than or <strong>e</strong>qual to)<br />
88f586e767b7b224bdb1a178455668a2475cfc75rbowen The <em>TestString</em> is treated as an integer, and is
88f586e767b7b224bdb1a178455668a2475cfc75rbowen numerically compared to the <em>CondPattern</em>. True if
88f586e767b7b224bdb1a178455668a2475cfc75rbowen the <em>TestString</em> is numerically greater than or equal
88f586e767b7b224bdb1a178455668a2475cfc75rbowen <strong>g</strong>reater <strong>t</strong>han)<br />
88f586e767b7b224bdb1a178455668a2475cfc75rbowen The <em>TestString</em> is treated as an integer, and is
88f586e767b7b224bdb1a178455668a2475cfc75rbowen numerically compared to the <em>CondPattern</em>. True if
88f586e767b7b224bdb1a178455668a2475cfc75rbowen <strong>l</strong>ess than or <strong>e</strong>qual to)<br />
88f586e767b7b224bdb1a178455668a2475cfc75rbowen The <em>TestString</em> is treated as an integer, and is
88f586e767b7b224bdb1a178455668a2475cfc75rbowen numerically compared to the <em>CondPattern</em>. True if
88f586e767b7b224bdb1a178455668a2475cfc75rbowen the <em>TestString</em> is numerically less than or equal
88f586e767b7b224bdb1a178455668a2475cfc75rbowen to the <em>CondPattern</em>. Avoid confusion with the
88f586e767b7b224bdb1a178455668a2475cfc75rbowen <strong>-l</strong> by using the <strong>-L</strong> or
88f586e767b7b224bdb1a178455668a2475cfc75rbowen The <em>TestString</em> is treated as an integer, and is
88f586e767b7b224bdb1a178455668a2475cfc75rbowen numerically compared to the <em>CondPattern</em>. True if
88f586e767b7b224bdb1a178455668a2475cfc75rbowen <strong>-l</strong> by using the <strong>-L</strong> or
88f586e767b7b224bdb1a178455668a2475cfc75rbowen <li>You can perform various file attribute tests:
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>
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>
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen <li>'<strong>-H</strong>' (is symbolic link, bash convention)<br />
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen Treats the <em>TestString</em> as a pathname and tests
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen whether or not it exists, and is a symbolic link. May also
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen <strong>-h</strong> if there's a possibility of confusion
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen <li>'<strong>-L</strong>' (is symbolic link, bash convention)<br />
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen Treats the <em>TestString</em> as a pathname and tests
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen whether or not it exists, and is a regular file with size greater
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen than zero.</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
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor subrequest to do the check, so use it with care -
60177b97ef90c0dfb6e45d2d38c609d488ef6315covener it can impact your server's performance!</p>
60177b97ef90c0dfb6e45d2d38c609d488ef6315covener <p> This flag <em>only</em> returns information about things
60177b97ef90c0dfb6e45d2d38c609d488ef6315covener like access control, authentication, and authorization. This flag
60177b97ef90c0dfb6e45d2d38c609d488ef6315covener <em>does not</em> return information about the status code the
60177b97ef90c0dfb6e45d2d38c609d488ef6315covener configured handler (static file, CGI, proxy, etc.) would have
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen <li>'<strong>-x</strong>' (has e<strong>x</strong>ecutable
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen permissions)<br />
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen Treats the <em>TestString</em> as a pathname and tests
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen whether or not it exists, and has executable permissions.
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen These permissions are determined according to
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen the underlying OS.</li>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive All of these tests can
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive also be prefixed by an exclamation mark ('!') to
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive negate their meaning.
c094add0a23fe1120fd33711ba2e2d084f5629a1sf <p>If the <em>TestString</em> has the special value <code>expr</code>, the
44af3968bb363f5a956a86cc90e591384a2f07b5rbowen In the below example, <code>-strmatch</code> is used to
44af3968bb363f5a956a86cc90e591384a2f07b5rbowen compare the <code>REFERER</code> against the site hostname,
44af3968bb363f5a956a86cc90e591384a2f07b5rbowen to block unwanted hotlinking.
44af3968bb363f5a956a86cc90e591384a2f07b5rbowen RewriteCond expr "! %{HTTP_REFERER} -strmatch '*://%{HTTP_HOST}/*'"<br />
44af3968bb363f5a956a86cc90e591384a2f07b5rbowen RewriteRule ^/images - [F]
3a257106808eabaefbb483bdc6273e7af062ead8humbedooh </highlight>
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi <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:
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor This makes the test case-insensitive - differences
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi between 'A-Z' and 'a-z' are ignored, both in the
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive expanded <em>TestString</em> and the <em>CondPattern</em>.
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive This flag is effective only for comparisons between
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive <em>TestString</em> and <em>CondPattern</em>. It has no
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive effect on filesystem and subrequest checks.</li>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin Use this to combine rule conditions with a local OR
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor instead of the implicit AND. Typical example:
025069f3f8c6b59e730a72c229329dfad5a28424rbowenRewriteCond %{REMOTE_HOST} ^host1 [OR]
025069f3f8c6b59e730a72c229329dfad5a28424rbowenRewriteCond %{REMOTE_HOST} ^host2 [OR]
025069f3f8c6b59e730a72c229329dfad5a28424rbowenRewriteCond %{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>
8ae7b19a7c6b1415b2be0b45e91d7ba6e8ed010drbowenRewriteCond %{HTTP_USER_AGENT} (iPhone|Blackberry|Android)
8ae7b19a7c6b1415b2be0b45e91d7ba6e8ed010drbowenRewriteRule ^/$ /homepage.mobile.html [L]
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfsliveRewriteRule ^/$ /homepage.std.html [L]
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor <p>Explanation: If you use a browser which identifies itself
8ae7b19a7c6b1415b2be0b45e91d7ba6e8ed010drbowen as a mobile browser (note that the example is incomplete, as
8ae7b19a7c6b1415b2be0b45e91d7ba6e8ed010drbowen there are many other mobile platforms), the mobile version of
8ae7b19a7c6b1415b2be0b45e91d7ba6e8ed010drbowen the homepage is served. Otherwise, the standard page is served.
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
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor rewriting workhorse. The directive can occur more than once,
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin with each instance defining a single rewrite rule. The
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin order in which these rules are defined is important - this is the order
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin in which they will be applied at run-time.</p>
630c456b6461158be6cc5c5483735e27b13b4ad5nd <p><a id="patterns" name="patterns"><em>Pattern</em></a> is
4e9c3b56a42ce3d88366146f3f71194f64148447humbedooh expression</a>. On the first RewriteRule, it is matched against
ae382386f18506586972cdd63c09bb27a1685062nd the (%-decoded) <a href="directive-dict.html#Syntax">URL-path</a> (or
ae382386f18506586972cdd63c09bb27a1685062nd <a href="directive-dict.html#Syntax">file-path</a>, depending
4e9c3b56a42ce3d88366146f3f71194f64148447humbedooh on the context) of the request. Subsequent patterns are matched against the
4e9c3b56a42ce3d88366146f3f71194f64148447humbedooh output of the last matching RewriteRule.</p>
81fb9d8829c87f498aad9ae764e98d1f60fbfd1crbowen<note><title><a id="what_is_matched" name="what_is_matched">What is matched?</a></title>
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim <p>In <directive module="core">VirtualHost</directive> context,
944950774d28288e298c396e6f06fa4ba18e4ca0covener The <em>Pattern</em> will initially be matched against the part of the
944950774d28288e298c396e6f06fa4ba18e4ca0covener URL after the hostname and port, and before the query string (e.g. "/app1/index.html").</p>
944950774d28288e298c396e6f06fa4ba18e4ca0covener <p>In <directive module="core">Directory</directive> and htaccess context,
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim the <em>Pattern</em> will initially be matched against the
2099e7c30b65c2015f24fdc9b9c5e23414467d0ahumbedooh <em>filesystem</em> path, after removing the prefix that led the server
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim to the current <directive>RewriteRule</directive> (e.g. "app1/index.html"
944950774d28288e298c396e6f06fa4ba18e4ca0covener or "index.html" depending on where the directives are defined).</p>
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener <p>If you wish to match against the hostname, port, or query string, use a
96147932f199be4ad038778e702c13a2f79051c0slive <directive module="mod_rewrite">RewriteCond</directive> with the
96147932f199be4ad038778e702c13a2f79051c0slive <code>%{HTTP_HOST}</code>, <code>%{SERVER_PORT}</code>, or
944950774d28288e298c396e6f06fa4ba18e4ca0covener <code>%{QUERY_STRING}</code> variables respectively.</p>
25685ff9c2ac6ff8876a4d23bc6091432310f307covenerhref="/howto/htaccess.html">.htaccess</a> files and in <directive type="section"
944950774d28288e298c396e6f06fa4ba18e4ca0covenermodule="core">Directory</directive> sections, with some additional
944950774d28288e298c396e6f06fa4ba18e4ca0covenercomplexity.</li>
944950774d28288e298c396e6f06fa4ba18e4ca0covener<li>To enable the rewrite engine in this context, you need to set
944950774d28288e298c396e6f06fa4ba18e4ca0covener"<code>Options FollowSymLinks</code>" must be enabled. If your
944950774d28288e298c396e6f06fa4ba18e4ca0coveneradministrator has disabled override of <code>FollowSymLinks</code> for
944950774d28288e298c396e6f06fa4ba18e4ca0covenera user's directory, then you cannot use the rewrite engine. This
944950774d28288e298c396e6f06fa4ba18e4ca0covenerrestriction is required for security reasons.</li>
944950774d28288e298c396e6f06fa4ba18e4ca0covener<li>When using the rewrite engine in <code>.htaccess</code> files the
944950774d28288e298c396e6f06fa4ba18e4ca0covenerper-directory prefix (which always is the same for a specific
cb85fb2fa6a3fd1fea1eda25ffc2a62190f0ff9crbowendirectory) is automatically <em>removed</em> for the RewriteRule pattern matching
944950774d28288e298c396e6f06fa4ba18e4ca0covenerand automatically <em>added</em> after any relative (not starting with a
cb85fb2fa6a3fd1fea1eda25ffc2a62190f0ff9crbowenslash or protocol name) substitution encounters the end of a rule set.
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jimSee the <directive module="mod_rewrite">RewriteBase</directive>
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jimdirective for more information regarding what prefix will be added back to
dbe68b8c92b9bd76e692c045d52820cb55efd6abrbowenrelative substitutions.</li>
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim<li> If you wish to match against the full URL-path in a per-directory
944950774d28288e298c396e6f06fa4ba18e4ca0covener(htaccess) RewriteRule, use the <code>%{REQUEST_URI}</code> variable in
944950774d28288e298c396e6f06fa4ba18e4ca0covener<li>The removed prefix always ends with a slash, meaning the matching occurs against a string which
25685ff9c2ac6ff8876a4d23bc6091432310f307covener<em>never</em> has a leading slash. Therefore, a <em>Pattern</em> with <code>^/</code> never
944950774d28288e298c396e6f06fa4ba18e4ca0covenermatches in per-directory context.</li>
944950774d28288e298c396e6f06fa4ba18e4ca0covener<li>Although rewrite rules are syntactically permitted in <directive
944950774d28288e298c396e6f06fa4ba18e4ca0covenertype="section" module="core">Location</directive> and <directive
944950774d28288e298c396e6f06fa4ba18e4ca0covenertype="section" module="core">Files</directive> sections, this
944950774d28288e298c396e6f06fa4ba18e4ca0covenershould never be necessary and is unsupported.</li>
70f2730533c8592263435354e66d9dbaf4d6361bslive expressions</glossary>, see
206b5dce9e48924aa9f12ce87f14856a4cd3fb68takashi <p>In mod_rewrite, the NOT character
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor ('<code>!</code>') is also available as a possible pattern
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin prefix. This enables you to negate a pattern; to say, for instance:
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive ``<em>if the current URL does <strong>NOT</strong> match this
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive pattern</em>''. This can be used for exceptional cases, where
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive it is easier to match the negative pattern, or as a last
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive default rule.</p>
5f18f92c1354462df6dc2ba38277a953fa700b13gryzorWhen using the NOT character to negate a pattern, you cannot include
5f18f92c1354462df6dc2ba38277a953fa700b13gryzorgrouped wildcard parts in that pattern. This is because, when the
5f18f92c1354462df6dc2ba38277a953fa700b13gryzorpattern does NOT match (ie, the negation matches), there are no
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirincontents for the groups. Thus, if negated patterns are used, you
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirincannot use <code>$N</code> in the substitution string!
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
c83db09d27363318d4c595564937d199ac6cbf71covener to be delivered to the client. Substitutions are only
c83db09d27363318d4c595564937d199ac6cbf71covener treated as a file-system path when the rule is configured in
c83db09d27363318d4c595564937d199ac6cbf71covener server (virtualhost) context and the first component of the
dabdff4f01f31a31f3c96a3157f25dea49a1cf32humbedooh path in the substitution exists in the file-system</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>
80b223c8e14db3a06c6d1776b92c55a2257b31bbhumbedooh exists at the root or your file-system (or, in the case of
80b223c8e14db3a06c6d1776b92c55a2257b31bbhumbedooh using rewrites in a <code>.htaccess</code> file, relative to
80b223c8e14db3a06c6d1776b92c55a2257b31bbhumbedooh your document root), 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
dc585e0df783dd91b8121ea1cfa743cea2ac12fdcovener the path.</dd>
dbe68b8c92b9bd76e692c045d52820cb55efd6abrbowen <p>In addition to plain text, the <em>Substitution</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
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor <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>
3bd4f2a469a28a479ba4336e0494802697e67e6arbowen <p>Rewrite rules are applied to the results of previous rewrite
3bd4f2a469a28a479ba4336e0494802697e67e6arbowen rules, in the order in which they are defined
198ed7e689ada03d3236a3d0e709245d2b07dfa2humbedooh in the config file. The URL-path or file-system path (see <a
81fb9d8829c87f498aad9ae764e98d1f60fbfd1crbowen href="#what_is_matched">"What is matched?"</a>, above) is <strong>completely
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive replaced</strong> by the <em>Substitution</em> and the
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin rewriting process continues until all rules have been applied,
81fb9d8829c87f498aad9ae764e98d1f60fbfd1crbowen or it is explicitly terminated by an
3bd4f2a469a28a479ba4336e0494802697e67e6arbowen <a href="/rewrite/flags.html#flag_l"><code><strong>L</strong></code> flag</a>,
3bd4f2a469a28a479ba4336e0494802697e67e6arbowen or other flag which implies immediate termination, such as
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>
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor directive. <em>Flags</em> is a comma-separated list, surround by square
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen brackets, of any of the flags in the following table. More
2f44538c88c5310bebb17a39b171487315a45624lgentis details, and examples, for each flag, are available in the <a
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen href="/rewrite/flags.html">Rewrite Flags document</a>.</p>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Escape non-alphanumeric characters <em>before</em> applying
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen href="/rewrite/flags.html#flag_b">details ...</a></em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Rule is chained to the following rule. If the rule fails,
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen href="/rewrite/flags.html#flag_c">details ...</a></em></td>
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim <td>Sets a cookie in the client browser. Full syntax is:
ab058bbbd467a540b481cb3c6443035e4a39ef48rbowen CO=<em>NAME</em>:<em>VAL</em>:<em>domain</em>[:<em>lifetime</em>[:<em>path</em>[:<em>secure</em>[:<em>httponly</em>]]]] <em><a href="/rewrite/flags.html#flag_co">details ...</a></em>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Causes the PATH_INFO portion of the rewritten URI to be
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim discarded. <em><a href="/rewrite/flags.html#flag_dpi">details
cc253dfdd0c1682d55910b7f085fd6a06d224e80rbowen <td>Stop the rewriting process immediately and don't apply any
cc253dfdd0c1682d55910b7f085fd6a06d224e80rbowen more rules. Also prevents further execution of rewrite rules
cc253dfdd0c1682d55910b7f085fd6a06d224e80rbowen in per-directory and .htaccess context. (Available in 2.3.9 and later)
e3f22cc532d5d8b11560f70e994d6ac281b35b50rbowen <em><a href="/rewrite/flags.html#flag_end">details ...</a></em></td>
39d67f66729a7008c1e73d65a81e778ce819a227rjung <td>Causes an environment variable <em>VAR</em> to be set (to the
12b26f433fd7d6fc9f76413d7c2cabf4fa5cb300sf value <em>VAL</em> if provided). The form !<em>VAR</em> causes
de2d5641f213f49317857e989e21a86c49f2b96brbowen <em><a href="/rewrite/flags.html#flag_e">details ...</a></em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Returns a 403 FORBIDDEN response to the client browser.
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <em><a href="/rewrite/flags.html#flag_f">details ...</a></em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Returns a 410 GONE response to the client browser. <em><a
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen href="/rewrite/flags.html#flag_g">details ...</a></em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Causes the resulting URI to be sent to the specified
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen href="/rewrite/flags.html#flag_h">details ...</a></em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Stop the rewriting process immediately and don't apply any
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen more rules. Especially note caveats for per-directory and
e3f22cc532d5d8b11560f70e994d6ac281b35b50rbowen href="/rewrite/flags.html#flag_l">details ...</a></em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Re-run the rewriting process, starting again with the first
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen rule, using the result of the ruleset so far as a starting
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen point. <em><a href="/rewrite/flags.html#flag_n">details
9acc64833096d98e78737366e67c31de7a128801rbowen <td>Makes the pattern comparison case-insensitive.
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <em><a href="/rewrite/flags.html#flag_nc">details ...</a></em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Prevent mod_rewrite from applying hexcode escaping of
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen special characters in the result of the rewrite. <em><a
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen href="/rewrite/flags.html#flag_ne">details ...</a></em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Causes a rule to be skipped if the current request is an
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen href="/rewrite/flags.html#flag_ns">details ...</a></em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Force the substitution URL to be internally sent as a proxy
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen request. <em><a href="/rewrite/flags.html#flag_p">details
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Forces the resulting URI to be passed back to the URL
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen mapping engine for processing of other URI-to-filename
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen href="/rewrite/flags.html#flag_pt">details ...</a></em></td>
4988bb943ad0c9b851eae6a2e5d9a59529630b96rbowen <td>Appends any query string from the original request URL to
4988bb943ad0c9b851eae6a2e5d9a59529630b96rbowen any query string created in the rewrite target.<em><a
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen href="/rewrite/flags.html#flag_qsa">details ...</a></em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Discard any query string attached to the incoming URI.
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Forces an external redirect, optionally with the specified
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen href="/rewrite/flags.html#flag_r">details ...</a></em>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Tells the rewriting engine to skip the next <em>num</em>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen href="/rewrite/flags.html#flag_s">details ...</a></em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Force the <glossary>MIME-type</glossary> of the target file
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen href="/rewrite/flags.html#flag_t">details ...</a></em></td>
de68ca33425122cf4a880859013e08e84f8143a5covener<p> When the substitution string begins with a string
de68ca33425122cf4a880859013e08e84f8143a5covenerresembling "/~user" (via explicit text or backreferences), mod_rewrite performs
5f18f92c1354462df6dc2ba38277a953fa700b13gryzorhome directory expansion independent of the presence or configuration
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>
b1136023d7083e8ada7ee2a7f8563383568d0e9cnoirin <p>Here are all possible substitution combinations and their
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive meanings:</p>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive for request ``<code>GET
34212fdb21f03f4e180a3226f83e39af0371d7dbrbowen<td>http://thishost/otherpath/pathinfo via external redirection</td>
34212fdb21f03f4e180a3226f83e39af0371d7dbrbowen<td>^/somepath(.*) http://thishost/otherpath$1 [R]</td>
34212fdb21f03f4e180a3226f83e39af0371d7dbrbowen<td>http://thishost/otherpath/pathinfo via external redirection</td>
34212fdb21f03f4e180a3226f83e39af0371d7dbrbowen<td>^/somepath(.*) http://thishost/otherpath$1 [P]</td>
34212fdb21f03f4e180a3226f83e39af0371d7dbrbowen<td>http://otherhost/otherpath/pathinfo via external redirection</td>
34212fdb21f03f4e180a3226f83e39af0371d7dbrbowen<td>^/somepath(.*) http://otherhost/otherpath$1 [R]</td>
34212fdb21f03f4e180a3226f83e39af0371d7dbrbowen<td>http://otherhost/otherpath/pathinfo via external redirection (the [R] flag is redundant)</td>
34212fdb21f03f4e180a3226f83e39af0371d7dbrbowen<td>^/somepath(.*) http://otherhost/otherpath$1 [P]</td>
34212fdb21f03f4e180a3226f83e39af0371d7dbrbowen<td>http://otherhost/otherpath/pathinfo via internal proxy</td>
8c3a1a087bdee9c6156951ef748adee127ab0bd1humbedooh (<code>/physical/path/to/somepath/.htaccess</code>, with
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive for request ``<code>GET
5f18f92c1354462df6dc2ba38277a953fa700b13gryzor /somepath/localpath/pathinfo</code>'':</strong><br />
34212fdb21f03f4e180a3226f83e39af0371d7dbrbowen<td>http://thishost/somepath/otherpath/pathinfo via external
34212fdb21f03f4e180a3226f83e39af0371d7dbrbowenredirection</td>
34212fdb21f03f4e180a3226f83e39af0371d7dbrbowen<td>http://thishost/otherpath/pathinfo via external redirection</td>
34212fdb21f03f4e180a3226f83e39af0371d7dbrbowen<td>^localpath(.*) http://thishost/otherpath$1 [R]</td>
34212fdb21f03f4e180a3226f83e39af0371d7dbrbowen<td>http://thishost/otherpath/pathinfo via external redirection</td>
34212fdb21f03f4e180a3226f83e39af0371d7dbrbowen<td>^localpath(.*) http://thishost/otherpath$1 [P]</td>
34212fdb21f03f4e180a3226f83e39af0371d7dbrbowen<td>http://otherhost/otherpath/pathinfo via external redirection</td>
34212fdb21f03f4e180a3226f83e39af0371d7dbrbowen<td>^localpath(.*) http://otherhost/otherpath$1 [R]</td>
34212fdb21f03f4e180a3226f83e39af0371d7dbrbowen<td>http://otherhost/otherpath/pathinfo via external redirection (the [R] flag is redundant)</td>
34212fdb21f03f4e180a3226f83e39af0371d7dbrbowen<td>^localpath(.*) http://otherhost/otherpath$1 [P]</td>
34212fdb21f03f4e180a3226f83e39af0371d7dbrbowen<td>http://otherhost/otherpath/pathinfo via internal proxy</td>
013e1ddd21f2142a369c9a9a0eeb6c6a0bc3fcf3patrikj </directivesynopsis>
1c47b0c72c991a6f0ad172c74df0936fe13d6fbfslive</modulesynopsis>