mod_rewrite.xml revision add05d0fdfd18b515383629b1b58130ada068dff
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein<!DOCTYPE modulesynopsis SYSTEM "/style/modulesynopsis.dtd">
32098293b78922a5fbd10906afa28624820d3756Tinderbox User<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein<!-- $LastChangedRevision$ -->
5347c0fcb04eaea19d9f39795646239f487c6207Tinderbox User Licensed to the Apache Software Foundation (ASF) under one or more
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein contributor license agreements. See the NOTICE file distributed with
d6fa26d0adaec6c910115be34fe7a5a5f402c14fMark Andrews this work for additional information regarding copyright ownership.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein The ASF licenses this file to You under the Apache License, Version 2.0
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein (the "License"); you may not use this file except in compliance with
cd32f419a8a5432fbb139f56ee73cbf68b9350ccTinderbox User the License. You may obtain a copy of the License at
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein Unless required by applicable law or agreed to in writing, software
cd32f419a8a5432fbb139f56ee73cbf68b9350ccTinderbox User distributed under the License is distributed on an "AS IS" BASIS,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein See the License for the specific language governing permissions and
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein limitations under the License.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<description>Provides a rule-based rewriting engine to rewrite requested
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark AndrewsURLs on the fly</description>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User <p>The <module>mod_rewrite</module> module uses a rule-based rewriting
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt engine, based on a PCRE regular-expression parser, to rewrite requested URLs on
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt the fly. By default, <module>mod_rewrite</module> maps a URL to a filesystem
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User path. However, it can also be used to redirect one URL to another URL, or
164ade1482251e1da962b42e5bf0d3aa02a11e03Tinderbox User to invoke an internal proxy fetch.</p>
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt <p><module>mod_rewrite</module> provides a flexible and powerful way to
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt manipulate URLs using an unlimited number of rules. Each rule can have an
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt unlimited number of attached rule conditions, to allow you to rewrite URL
33c9436ef1a43d3c0fc3d9be9b4b0509daa83223Tinderbox User based on server variables, environment variables, HTTP headers, or time
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt <p><module>mod_rewrite</module> operates on the full URL path, including the
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt path-info section. A rewrite rule can be invoked in
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt <code>httpd.conf</code> or in <code>.htaccess</code>. The path generated
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt by a rewrite rule can include a query string, or can lead to internal
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt sub-processing, external request redirection, or internal proxy
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt throughput.</p>
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein <p>Further details, discussion, and examples, are provided in the
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User <a href="/rewrite/">detailed mod_rewrite documentation</a>.</p>
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt <p><module>mod_rewrite</module> offers detailed logging of its actions
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt at the <code>trace1</code> to <code>trace8</code> log levels. The
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User log level can be set specifically for <module>mod_rewrite</module>
0da02c26a6631c25f075a8e4ac6de9e58f49a0c2Tinderbox User using the <directive module="core">LogLevel</directive> directive: Up to
0da02c26a6631c25f075a8e4ac6de9e58f49a0c2Tinderbox User level <code>debug</code>, no actions are logged, while <code>trace8</code>
0da02c26a6631c25f075a8e4ac6de9e58f49a0c2Tinderbox User means that practically all actions are logged.</p>
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User Using a high trace log level for <module>mod_rewrite</module>
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User will slow down your Apache HTTP Server dramatically! Use a log
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User level higher than <code>trace2</code> only for debugging!
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User LogLevel alert rewrite:trace3
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt </highlight>
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User <p>Those familiar with earlier versions of
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User <module>mod_rewrite</module> will no doubt be looking for the
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User <code>RewriteLog</code> and <code>RewriteLogLevel</code>
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt directives. This functionality has been completely replaced by the
33c9436ef1a43d3c0fc3d9be9b4b0509daa83223Tinderbox User new per-module logging configuration mentioned above.
33c9436ef1a43d3c0fc3d9be9b4b0509daa83223Tinderbox User <p>To get just the <module>mod_rewrite</module>-specific log
33c9436ef1a43d3c0fc3d9be9b4b0509daa83223Tinderbox User messages, pipe the log file through grep:</p>
33c9436ef1a43d3c0fc3d9be9b4b0509daa83223Tinderbox User tail -f error_log|fgrep '[rewrite:'
33c9436ef1a43d3c0fc3d9be9b4b0509daa83223Tinderbox User<directivesynopsis>
33c9436ef1a43d3c0fc3d9be9b4b0509daa83223Tinderbox User<description>Enables or disables runtime rewriting engine</description>
33c9436ef1a43d3c0fc3d9be9b4b0509daa83223Tinderbox User<contextlist><context>server config</context><context>virtual host</context>
33c9436ef1a43d3c0fc3d9be9b4b0509daa83223Tinderbox User<context>directory</context><context>.htaccess</context></contextlist>
33c9436ef1a43d3c0fc3d9be9b4b0509daa83223Tinderbox User <p>The <directive>RewriteEngine</directive> directive enables or
33c9436ef1a43d3c0fc3d9be9b4b0509daa83223Tinderbox User disables the runtime rewriting engine. If it is set to
33c9436ef1a43d3c0fc3d9be9b4b0509daa83223Tinderbox User <code>off</code> this module does no runtime processing at
33c9436ef1a43d3c0fc3d9be9b4b0509daa83223Tinderbox User all. It does not even update the <code>SCRIPT_URx</code>
33c9436ef1a43d3c0fc3d9be9b4b0509daa83223Tinderbox User environment variables.</p>
33c9436ef1a43d3c0fc3d9be9b4b0509daa83223Tinderbox User <p>Use this directive to disable rules in a particular contact,
a1ff871f78b7d907d6fc3a382beea2a640fe8423Tinderbox User rather than commenting out all the <directive
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User module="mod_rewrite">RewriteRule</directive> directives.</p>
8a48b6b9b6fa8486f24b22d1972b2b6ebb36a4a4Tinderbox User <p>Note that rewrite configurations are not
0da02c26a6631c25f075a8e4ac6de9e58f49a0c2Tinderbox User inherited by virtual hosts. This means that you need to have a
8a48b6b9b6fa8486f24b22d1972b2b6ebb36a4a4Tinderbox User <code>RewriteEngine on</code> directive for each virtual host
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User in which you wish to use rewrite rules.</p>
8a48b6b9b6fa8486f24b22d1972b2b6ebb36a4a4Tinderbox User <p><directive>RewriteMap</directive> directives of the type <code>prg</code>
8a48b6b9b6fa8486f24b22d1972b2b6ebb36a4a4Tinderbox User are not started during server initialization if they're defined in a
8a48b6b9b6fa8486f24b22d1972b2b6ebb36a4a4Tinderbox User context that does not have <directive>RewriteEngine</directive> set to
8a48b6b9b6fa8486f24b22d1972b2b6ebb36a4a4Tinderbox User</directivesynopsis>
8a48b6b9b6fa8486f24b22d1972b2b6ebb36a4a4Tinderbox User<directivesynopsis>
8a48b6b9b6fa8486f24b22d1972b2b6ebb36a4a4Tinderbox User<description>Sets some special options for the rewrite engine</description>
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User<syntax>RewriteOptions <var>Options</var></syntax>
8a48b6b9b6fa8486f24b22d1972b2b6ebb36a4a4Tinderbox User<contextlist><context>server config</context><context>virtual host</context>
8a48b6b9b6fa8486f24b22d1972b2b6ebb36a4a4Tinderbox User<context>directory</context><context>.htaccess</context></contextlist>
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User <p>The <directive>RewriteOptions</directive> directive sets some
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User special options for the current per-server or per-directory
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User configuration. The <em>Option</em> string can currently
a1ff871f78b7d907d6fc3a382beea2a640fe8423Tinderbox User only be one of the following:</p>
164ade1482251e1da962b42e5bf0d3aa02a11e03Tinderbox User <p>This forces the current configuration to inherit the
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User configuration of the parent. In per-virtual-server context,
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User this means that the maps, conditions and rules of the main
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User server are inherited. In per-directory context this means
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt that conditions and rules of the parent directory's
abe69df9a7de5cda07a2b8e19e8b7c981bcd7a9dTinderbox User <directive type="section" module="core">Directory</directive>
abe69df9a7de5cda07a2b8e19e8b7c981bcd7a9dTinderbox User sections are inherited. The inherited rules are virtually copied
abe69df9a7de5cda07a2b8e19e8b7c981bcd7a9dTinderbox User to the section where this directive is being used. If used in
abe69df9a7de5cda07a2b8e19e8b7c981bcd7a9dTinderbox User combination with local rules, the inherited rules are copied behind
abe69df9a7de5cda07a2b8e19e8b7c981bcd7a9dTinderbox User the local rules. The position of this directive - below or above
abe69df9a7de5cda07a2b8e19e8b7c981bcd7a9dTinderbox User of local rules - has no influence on this behavior. If local
abe69df9a7de5cda07a2b8e19e8b7c981bcd7a9dTinderbox User rules forced the rewriting to stop, the inherited rules won't
abe69df9a7de5cda07a2b8e19e8b7c981bcd7a9dTinderbox User be processed.</p>
abe69df9a7de5cda07a2b8e19e8b7c981bcd7a9dTinderbox User Rules inherited from the parent scope are applied
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User <strong>after</strong> rules specified in the child scope.
164ade1482251e1da962b42e5bf0d3aa02a11e03Tinderbox User <p> Like <code>Inherit</code> above, but the rules from the parent scope
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User are applied <strong>before</strong> rules specified in the child scope.
abe69df9a7de5cda07a2b8e19e8b7c981bcd7a9dTinderbox User Available in Apache HTTP Server 2.3.10 and later.</p>
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt <p>By default, <module>mod_rewrite</module> will ignore URLs that map to a
164ade1482251e1da962b42e5bf0d3aa02a11e03Tinderbox User directory on disk but lack a trailing slash, in the expectation that
99b30e26a6beb9092557cc9e5370b517309bff6eTinderbox User the <module>mod_dir</module> module will issue the client with a redirect to
99b30e26a6beb9092557cc9e5370b517309bff6eTinderbox User the canonical URL with a trailing slash.</p>
3b15473cedf41d48904f5b07bdc5e87afff6b58cTinderbox User <p>When the <directive module="mod_dir">DirectorySlash</directive> directive
3b15473cedf41d48904f5b07bdc5e87afff6b58cTinderbox User is set to off, the <code>AllowNoSlash</code> option can be enabled to ensure
3b15473cedf41d48904f5b07bdc5e87afff6b58cTinderbox User that rewrite rules are no longer ignored. This option makes it possible to
3b15473cedf41d48904f5b07bdc5e87afff6b58cTinderbox User apply rewrite rules within .htaccess files that match the directory without
3b15473cedf41d48904f5b07bdc5e87afff6b58cTinderbox User a trailing slash, if so desired. Available in Apache HTTP Server 2.4.0 and
99b30e26a6beb9092557cc9e5370b517309bff6eTinderbox User <p>When <directive module="mod_rewrite">RewriteRule</directive>
99b30e26a6beb9092557cc9e5370b517309bff6eTinderbox User is used in <code>VirtualHost</code> or server context with
99b30e26a6beb9092557cc9e5370b517309bff6eTinderbox User version 2.2.22 or later of httpd, <module>mod_rewrite</module>
99b30e26a6beb9092557cc9e5370b517309bff6eTinderbox User will only process the rewrite rules if the request URI is a <a
99b30e26a6beb9092557cc9e5370b517309bff6eTinderbox User href="/directive-dict.html#Syntax">URL-path</a>. This avoids
ffe29868b4bbc64953fc5d0de51f988c20158967Tinderbox User some security issues where particular rules could allow
ffe29868b4bbc64953fc5d0de51f988c20158967Tinderbox User "surprising" pattern expansions (see <a
ffe29868b4bbc64953fc5d0de51f988c20158967Tinderbox User href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-3368">CVE-2011-3368</a>
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-4317">CVE-2011-4317</a>).
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User To lift the restriction on matching a URL-path, the
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt <code>AllowAnyURI</code> option can be enabled, and
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt <module>mod_rewrite</module> will apply the rule set to any
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User request URI string, regardless of whether that string matches
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt the URL-path grammar required by the HTTP specification.</p>
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User <p>Enabling this option will make the server vulnerable to
7911e6f9de303bca5a3d8b34f4330c8f7cecffaeTinderbox User security issues if used with rewrite rules which are not
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt carefully authored. It is <strong>strongly recommended</strong>
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt that this option is not used. In particular, beware of input
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt strings containing the '<code>@</code>' character which could
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User change the interpretation of the transformed URI, as per the
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt above CVE names.</p>
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein <p>With this option, the value of <directive module="mod_rewrite"
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein >RewriteBase</directive> is copied from where it's explicitly defined
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein into any sub-directory or sub-location that doesn't define its own
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein <directive module="mod_rewrite">RewriteBase</directive>. Available in
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews Apache HTTP Server 2.5 and later only.</p>
cd32f419a8a5432fbb139f56ee73cbf68b9350ccTinderbox User</directivesynopsis>
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein<directivesynopsis>
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein<description>Defines a mapping function for key-lookup</description>
164ade1482251e1da962b42e5bf0d3aa02a11e03Tinderbox User<syntax>RewriteMap <em>MapName</em> <em>MapType</em>:<em>MapSource</em>
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein<contextlist><context>server config</context><context>virtual host</context>
<dd>Randomly selects an entry from a plain text file (<a href="/rewrite/rewritemap.html#rnd">Details ...</a>)</dd>
to avoid rewriting to http://example.com/opt/myapp-1.2.3/welcome.html
RewriteRule ^index\.html$ welcome.html
such as "/index.html". This notably excludes the
RewriteRule ...some special stuff for any of these hosts...
RewriteRule ^/$ /homepage.max.html [L]
RewriteRule ^/$ /homepage.min.html [L]
RewriteRule ^/$ /homepage.std.html [L]
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>