mod_rewrite.xml revision 70373b9ee042e7b3be82eee14b17f510fffdacc9
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<!DOCTYPE modulesynopsis SYSTEM "/style/modulesynopsis.dtd">
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<!-- $Revision: 1.28 $ -->
5a58787efeb02a1c3f06569d019ad81fd2efa06end Copyright 2002-2004 The Apache Software Foundation
5a58787efeb02a1c3f06569d019ad81fd2efa06end Licensed under the Apache License, Version 2.0 (the "License");
5a58787efeb02a1c3f06569d019ad81fd2efa06end you may not use this file except in compliance with the License.
5a58787efeb02a1c3f06569d019ad81fd2efa06end You may obtain a copy of the License at
52fff662005b1866a3ff09bb6c902800c5cc6dedjerenkrantz Unless required by applicable law or agreed to in writing, software
5a58787efeb02a1c3f06569d019ad81fd2efa06end distributed under the License is distributed on an "AS IS" BASIS,
5a58787efeb02a1c3f06569d019ad81fd2efa06end WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5a58787efeb02a1c3f06569d019ad81fd2efa06end See the License for the specific language governing permissions and
4b5981e276e93df97c34e4da05ca5cf8bbd937dand limitations under the License.
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd<description>Provides a rule-based rewriting engine to rewrite requested
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessURLs on the fly</description>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<compatibility>Available in Apache 1.3 and later</compatibility>
5a58787efeb02a1c3f06569d019ad81fd2efa06end <blockquote>
5a58787efeb02a1c3f06569d019ad81fd2efa06end <p>``The great thing about mod_rewrite is it gives you
5a58787efeb02a1c3f06569d019ad81fd2efa06end all the configurability and flexibility of Sendmail.
5a58787efeb02a1c3f06569d019ad81fd2efa06end The downside to mod_rewrite is that it gives you all
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess the configurability and flexibility of Sendmail.''</p>
5a58787efeb02a1c3f06569d019ad81fd2efa06end Apache Group</p>
5a58787efeb02a1c3f06569d019ad81fd2efa06end </blockquote>
5a58787efeb02a1c3f06569d019ad81fd2efa06end <blockquote>
5a58787efeb02a1c3f06569d019ad81fd2efa06end <p>`` Despite the tons of examples and docs,
f8dee27891059abb09ff5ca3fc5434f5719d22a0rbowen mod_rewrite is voodoo. Damned cool voodoo, but still
f8dee27891059abb09ff5ca3fc5434f5719d22a0rbowen voodoo. ''</p>
5a58787efeb02a1c3f06569d019ad81fd2efa06end bem@news.cmc.net</p>
5a58787efeb02a1c3f06569d019ad81fd2efa06end </blockquote>
5a58787efeb02a1c3f06569d019ad81fd2efa06end <p>Welcome to mod_rewrite, the Swiss Army Knife of URL
5a58787efeb02a1c3f06569d019ad81fd2efa06end manipulation!</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>This module uses a rule-based rewriting engine (based on a
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess regular-expression parser) to rewrite requested URLs on the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess fly. It supports an unlimited number of rules and an
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess unlimited number of attached rule conditions for each rule to
261c62b53a9c707c64c7824eed68b5463bd23e62nd provide a really flexible and powerful URL manipulation
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess mechanism. The URL manipulations can depend on various tests,
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess for instance server variables, environment variables, HTTP
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess headers, time stamps and even external database lookups in
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess various formats can be used to achieve a really granular URL
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess matching.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>This module operates on the full URLs (including the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess path-info part) both in per-server context
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess (<code>.htaccess</code>) and can even generate query-string
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess parts on result. The rewritten result can lead to internal
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess sub-processing, external request redirection or even to an
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess internal proxy throughput.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>But all this functionality and flexibility has its
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess drawback: complexity. So don't expect to understand this
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess entire module in just one day.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>This module was invented and originally written in April
dcf73e82ff6eda04fc24e50753631fd83bf61f3drbowen 1996 and gifted exclusively to the The Apache Group in July 1997
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess href="mailto:rse@engelschall.com"><code>rse@engelschall.com</code></a><br />
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess href="http://www.engelschall.com/"><code>www.engelschall.com</code></a>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<section id="Internal"><title>Internal Processing</title>
261c62b53a9c707c64c7824eed68b5463bd23e62nd <p>The internal processing of this module is very complex but
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess needs to be explained once even to the average user to avoid
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess common mistakes and to let you exploit its full
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess functionality.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>First you have to understand that when Apache processes a
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess HTTP request it does this in phases. A hook for each of these
261c62b53a9c707c64c7824eed68b5463bd23e62nd phases is provided by the Apache API. Mod_rewrite uses two of
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess these hooks: the URL-to-filename translation hook which is
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess used after the HTTP request has been read but before any
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess authorization starts and the Fixup hook which is triggered
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess after the authorization phases and after the per-directory
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess config files (<code>.htaccess</code>) have been read, but
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess before the content handler is activated.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>So, after a request comes in and Apache has determined the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess corresponding server (or virtual server) the rewriting engine
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess starts processing of all mod_rewrite directives from the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess per-server configuration in the URL-to-filename phase. A few
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess steps later when the final data directories are found, the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess per-directory configuration directives of mod_rewrite are
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess triggered in the Fixup phase. In both situations mod_rewrite
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess rewrites URLs either to new URLs or to filenames, although
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess there is no obvious distinction between them. This is a usage
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess of the API which was not intended to be this way when the API
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess was designed, but as of Apache 1.x this is the only way
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess mod_rewrite can operate. To make this point more clear
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess remember the following two points:</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <li>Although mod_rewrite rewrites URLs to URLs, URLs to
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess filenames and even filenames to filenames, the API
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess currently provides only a URL-to-filename hook. In Apache
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess 2.0 the two missing hooks will be added to make the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess processing more clear. But this point has no drawbacks for
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess the user, it is just a fact which should be remembered:
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess Apache does more in the URL-to-filename hook than the API
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess intends for it.</li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess Unbelievably mod_rewrite provides URL manipulations in
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>.htaccess</code> files, although these are reached
5a58787efeb02a1c3f06569d019ad81fd2efa06end a very long time after the URLs have been translated to
5a58787efeb02a1c3f06569d019ad81fd2efa06end filenames. It has to be this way because
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess processing has already reached this stage. In other
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess words: According to the API phases at this time it is too
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess late for any URL manipulations. To overcome this chicken
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess and egg problem mod_rewrite uses a trick: When you
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess mod_rewrite first rewrites the filename back to its
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess corresponding URL (which is usually impossible, but see
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess trick to achieve this) and then initiates a new internal
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess sub-request with the new URL. This restarts processing of
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess the API phases.
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>Again mod_rewrite tries hard to make this complicated
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess step totally transparent to the user, but you should
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess remember here: While URL manipulations in per-server
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess context are really fast and efficient, per-directory
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess rewrites are slow and inefficient due to this chicken and
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess egg problem. But on the other hand this is the only way
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess mod_rewrite can provide (locally restricted) URL
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess manipulations to the average user.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<section id="InternalRuleset"><title>Ruleset Processing</title>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>Now when mod_rewrite is triggered in these two API phases, it
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess reads the configured rulesets from its configuration
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess structure (which itself was either created on startup for
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess per-server context or during the directory walk of the Apache
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess kernel for per-directory context). Then the URL rewriting
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess engine is started with the contained ruleset (one or more
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess rules together with their conditions). The operation of the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess URL rewriting engine itself is exactly the same for both
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess configuration contexts. Only the final result processing is
261c62b53a9c707c64c7824eed68b5463bd23e62nd different. </p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>The order of rules in the ruleset is important because the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess rewriting engine processes them in a special (and not very
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess obvious) order. The rule is this: The rewriting engine loops
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess through the ruleset rule by rule (<directive
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess module="mod_rewrite">RewriteRule</directive> directives) and
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess when a particular rule matches it optionally loops through
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess existing corresponding conditions (<code>RewriteCond</code>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess directives). For historical reasons the conditions are given
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess first, and so the control flow is a little bit long-winded. See
261c62b53a9c707c64c7824eed68b5463bd23e62nd Figure 1 for more details.</p>
5a58787efeb02a1c3f06569d019ad81fd2efa06end height="385" alt="[Needs graphics capability to display]" /><br />
5a58787efeb02a1c3f06569d019ad81fd2efa06end <dfn>Figure 1:</dfn>The control flow through the rewriting ruleset
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>As you can see, first the URL is matched against the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <em>Pattern</em> of each rule. When it fails mod_rewrite
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess immediately stops processing this rule and continues with the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess next rule. If the <em>Pattern</em> matches, mod_rewrite looks
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess for corresponding rule conditions. If none are present, it
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess just substitutes the URL with a new value which is
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess constructed from the string <em>Substitution</em> and goes on
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess with its rule-looping. But if conditions exist, it starts an
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess inner loop for processing them in the order that they are
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess listed. For conditions the logic is different: we don't match
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess a pattern against the current URL. Instead we first create a
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess back-references, map lookups, <em>etc.</em> and then we try
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess to match <em>CondPattern</em> against it. If the pattern
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess doesn't match, the complete set of conditions and the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess corresponding rule fails. If the pattern matches, then the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess next condition is processed until no more conditions are
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess available. If all conditions match, processing is continued
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess with the substitution of the URL with
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<section id="quoting"><title>Quoting Special Characters</title>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>As of Apache 1.3.20, special characters in
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <em>TestString</em> and <em>Substitution</em> strings can be
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess escaped (that is, treated as normal characters without their
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess usual special meaning) by prefixing them with a slosh ('\')
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess character. In other words, you can include an actual
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess dollar-sign character in a <em>Substitution</em> string by
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess using '<code>\$</code>'; this keeps mod_rewrite from trying
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess to treat it as a backreference.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<section id="InternalBackRefs"><title>Regex Back-Reference Availability</title>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>One important thing here has to be remembered: Whenever you
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <em>CondPattern</em>, back-references are internally created
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>%N</code> (see below). These are available for creating
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess the strings <em>Substitution</em> and <em>TestString</em>.
5a58787efeb02a1c3f06569d019ad81fd2efa06end Figure 2 shows to which locations the back-references are
5a58787efeb02a1c3f06569d019ad81fd2efa06end transfered for expansion.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess height="179" alt="[Needs graphics capability to display]" /><br />
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <dfn>Figure 2:</dfn> The back-reference flow through a rule.
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>We know this was a crash course on mod_rewrite's internal
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess processing. But you will benefit from this knowledge when
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess reading the following documentation of the available
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess directives.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<section id="EnvVar"><title>Environment Variables</title>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>This module keeps track of two additional (non-standard)
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess CGI/SSI environment variables named <code>SCRIPT_URL</code>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <em>logical</em> Web-view to the current resource, while the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>SCRIPT_FILENAME</code> contain the <em>physical</em>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess System-view. </p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>Notice: These variables hold the URI/URL <em>as they were
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess initially requested</em>, <em>i.e.</em>, <em>before</em> any
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess rewriting. This is important because the rewriting process is
261c62b53a9c707c64c7824eed68b5463bd23e62nd primarily used to rewrite logical URLs to physical
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess pathnames.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessSCRIPT_NAME=/sw/lib/w3s/tree/global/u/rse/.www/index.html
261c62b53a9c707c64c7824eed68b5463bd23e62nd<section id="Solutions"><title>Practical Solutions</title>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>We also have an <a href="/misc/rewriteguide.html">URL
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess Rewriting Guide</a> available, which provides a collection of
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess practical solutions for URL-based problems. There you can
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess find real-life rulesets and additional information about
5a58787efeb02a1c3f06569d019ad81fd2efa06end mod_rewrite.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<directivesynopsis>
261c62b53a9c707c64c7824eed68b5463bd23e62nd<description>Enables or disables runtime rewriting engine</description>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<contextlist><context>server config</context><context>virtual host</context>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<context>directory</context><context>.htaccess</context></contextlist>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>The <directive>RewriteEngine</directive> directive enables or
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess disables the runtime rewriting engine. If it is set to
261c62b53a9c707c64c7824eed68b5463bd23e62nd <code>off</code> this module does no runtime processing at
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess all. It does not even update the <code>SCRIPT_URx</code>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess environment variables.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>Use this directive to disable the module instead of
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess commenting out all the <directive
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess module="mod_rewrite">RewriteRule</directive> directives!</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>Note that, by default, rewrite configurations are not
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess inherited. This means that you need to have a
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>RewriteEngine on</code> directive for each virtual host
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess in which you wish to use it.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</directivesynopsis>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<directivesynopsis>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<description>Sets some special options for the rewrite engine</description>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<contextlist><context>server config</context><context>virtual host</context>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<context>directory</context><context>.htaccess</context></contextlist>
261c62b53a9c707c64c7824eed68b5463bd23e62nd<compatibility><code>MaxRedirects</code> is available in Apache 2.0.45 and
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kesslater</compatibility>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>The <directive>RewriteOptions</directive> directive sets some
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess special options for the current per-server or per-directory
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess configuration. The <em>Option</em> strings can be one of the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess following:</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <dd>This forces the current configuration to inherit the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess configuration of the parent. In per-virtual-server context
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess this means that the maps, conditions and rules of the main
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess server are inherited. In per-directory context this means
261c62b53a9c707c64c7824eed68b5463bd23e62nd that conditions and rules of the parent directory's
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>.htaccess</code> configuration are inherited.</dd>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <dd>In order to prevent endless loops of internal redirects
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess issued by per-directory <directive module="mod_rewrite"
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess >RewriteRule</directive>s, <module>mod_rewrite</module> aborts
261c62b53a9c707c64c7824eed68b5463bd23e62nd the request after reaching a maximum number of such redirects and
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess responds with an 500 Internal Server Error. If you really need
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess more internal redirects than 10 per request, you may increase
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess the default to the desired value.</dd>
261c62b53a9c707c64c7824eed68b5463bd23e62nd</directivesynopsis>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<directivesynopsis>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<description>Sets the name of the file used for logging rewrite engine
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessprocessing</description>
261c62b53a9c707c64c7824eed68b5463bd23e62nd<contextlist><context>server config</context><context>virtual host</context>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</contextlist>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>The <directive>RewriteLog</directive> directive sets the name
5a58787efeb02a1c3f06569d019ad81fd2efa06end of the file to which the server logs any rewriting actions it
5a58787efeb02a1c3f06569d019ad81fd2efa06end performs. If the name does not begin with a slash
5a58787efeb02a1c3f06569d019ad81fd2efa06end ('<code>/</code>') then it is assumed to be relative to the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <em>Server Root</em>. The directive should occur only once per
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess server config.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<note> To disable the logging of
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess rewriting actions it is not recommended to set
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess although the rewriting engine does not then output to a
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess logfile it still creates the logfile output internally.
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <strong>This will slow down the server with no advantage
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess to the administrator!</strong> To disable logging either
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess remove or comment out the <directive>RewriteLog</directive>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessSee the <a href="/misc/security_tips.html">Apache Security Tips</a>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessdocument for details on why your security could be compromised if the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessdirectory where logfiles are stored is writable by anyone other than
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessthe user that starts the server.
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</directivesynopsis>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<directivesynopsis>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<description>Sets the verbosity of the log file used by the rewrite
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessengine</description>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<contextlist><context>server config</context><context>virtual host</context>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</contextlist>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>The <directive>RewriteLogLevel</directive> directive sets the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess verbosity level of the rewriting logfile. The default level 0
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess means no logging, while 9 or more means that practically all
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess actions are logged.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>To disable the logging of rewriting actions simply set
5a58787efeb02a1c3f06569d019ad81fd2efa06end<note> Using a high value for
f8dee27891059abb09ff5ca3fc5434f5719d22a0rbowen dramatically! Use the rewriting logfile at a
f8dee27891059abb09ff5ca3fc5434f5719d22a0rbowenRewriteLogLevel 3
f8dee27891059abb09ff5ca3fc5434f5719d22a0rbowen</directivesynopsis>
f8dee27891059abb09ff5ca3fc5434f5719d22a0rbowen<directivesynopsis>
f8dee27891059abb09ff5ca3fc5434f5719d22a0rbowen<description>Sets the name of the lock file used for <directive
f8dee27891059abb09ff5ca3fc5434f5719d22a0rbowensynchronization</description>
f8dee27891059abb09ff5ca3fc5434f5719d22a0rbowen<contextlist><context>server config</context></contextlist>
5a58787efeb02a1c3f06569d019ad81fd2efa06end <p>This directive sets the filename for a synchronization
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess lockfile which mod_rewrite needs to communicate with <directive
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <em>programs</em>. Set this lockfile to a local path (not on a
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess NFS-mounted device) when you want to use a rewriting
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess map-program. It is not required for other types of rewriting
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</directivesynopsis>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<directivesynopsis>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<description>Defines a mapping function for key-lookup</description>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<syntax>RewriteMap <em>MapName</em> <em>MapType</em>:<em>MapSource</em>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<contextlist><context>server config</context><context>virtual host</context>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess</contextlist>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<compatibility>The choice of different dbm types is available in
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessApache 2.0.41 and later</compatibility>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>The <directive>RewriteMap</directive> directive defines a
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess substitution strings by the mapping-functions to
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess insert/substitute fields through a key lookup. The source of
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess this lookup can be of various types.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>The <a id="mapfunc" name="mapfunc"><em>MapName</em></a> is
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess the name of the map and will be used to specify a
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess mapping-function for the substitution strings of a rewriting
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess rule via one of the following constructs:</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <strong><code>${</code> <em>MapName</em> <code>:</code>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <em>LookupKey</em> <code>|</code> <em>DefaultValue</em>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>When such a construct occurs the map <em>MapName</em> is
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess consulted and the key <em>LookupKey</em> is looked-up. If the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess key is found, the map-function construct is substituted by
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <em>SubstValue</em>. If the key is not found then it is
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess substituted by <em>DefaultValue</em> or by the empty string
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess path to valid regular file
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>This is the standard rewriting map feature where the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess either blank lines, comment lines (starting with a '#'
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess character) or pairs like the following - one per
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess## map.txt -- rewriting map
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessRalf.S.Engelschall rse # Bastard Operator From Hell
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessMr.Joe.Average joe # Mr. Average
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess path to valid regular file
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>This is identical to the Standard Plain Text variant
261c62b53a9c707c64c7824eed68b5463bd23e62nd above but with a special post-processing feature: After
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess looking up a value it is parsed according to contained
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess ``<code>|</code>'' characters which have the meaning of
a795ca2487c774aa6fe75c765a2bf17f969f7af7nd ``or''. In other words they indicate a set of
a795ca2487c774aa6fe75c765a2bf17f969f7af7nd alternatives from which the actual returned value is
a795ca2487c774aa6fe75c765a2bf17f969f7af7nd chosen randomly. Although this sounds crazy and useless,
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess it was actually designed for load balancing in a reverse
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess proxy situation where the looked up values are server
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess names. Example:</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess## map.txt -- rewriting map
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessstatic www1|www2|www3|www4
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessdynamic www5|www6
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>dbm[=<em>type</em>]</code>, MapSource: Unix filesystem
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess path to valid regular file
261c62b53a9c707c64c7824eed68b5463bd23e62nd <p>Here the source is a binary format DBM file containing
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess the same contents as a <em>Plain Text</em> format file, but
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess in a special representation which is optimized for really
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess fast lookups. The <em>type</em> can be sdbm, gdbm, ndbm, or
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess db depending on <a href="/install.html#dbm">compile-time
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess compile-time default will be chosen. You can create such a
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess file with any DBM tool or with the following Perl
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess script. Be sure to adjust it to create the appropriate
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess type of DBM. The example creates an NDBM file.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess## txt2dbm -- convert txt map to dbm format
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessuse NDBM_File;
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess($txtmap, $dbmmap) = @ARGV;
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessopen(TXT, "<$txtmap") or die "Couldn't open $txtmap!\n";
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kesstie (%DB, 'NDBM_File', $dbmmap,O_RDWR|O_TRUNC|O_CREAT, 0644)
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess or die "Couldn't create $dbmmap!\n";
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kesswhile (<TXT>) {
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess next if (/^\s*#/ or /^\s*$/);
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess $DB{$1} = $2 if (/^\s*(\S+)\s+(\S+)/);
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kessclose(TXT);
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>Here the source is an internal Apache function.
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess Currently you cannot create your own, but the following
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess functions already exists:</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess Converts the looked up key to all upper case.</li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess Converts the looked up key to all lower case.</li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess Translates special characters in the looked up key to
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess hex-encodings.</li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess Translates hex-encodings in the looked up key back to
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess special characters.</li>
a795ca2487c774aa6fe75c765a2bf17f969f7af7nd path to valid regular file
a795ca2487c774aa6fe75c765a2bf17f969f7af7nd <p>Here the source is a program, not a map file. To
a795ca2487c774aa6fe75c765a2bf17f969f7af7nd create it you can use the language of your choice, but
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess object-code or a script with the magic cookie trick
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess line).</p>
5a58787efeb02a1c3f06569d019ad81fd2efa06end <p>This program is started once at startup of the Apache
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd servers and then communicates with the rewriting engine
d05d0eb4ae6d2a5e513fc3bf2555ce33da416634nd file-handles. For each map-function lookup it will
7f5b59ccc63c0c0e3e678a168f09ee6a2f51f9d0nd receive the key to lookup as a newline-terminated string
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd looked-up value as a newline-terminated string on
5a58787efeb02a1c3f06569d019ad81fd2efa06end is no corresponding value for the given key). A trivial
# ...put here any transformations or lookups...
path. The default setting is; <directive>RewriteBase</directive> <em>physical-directory-path</em></p>
RewriteRule ^oldstuff\.html$ newstuff.html
RewriteRule ...some special stuff for any of these hosts...
RewriteRule ^/$ /homepage.max.html [L]
RewriteRule ^/$ /homepage.min.html [L]
RewriteRule ^/$ /homepage.std.html [L]
href="http://www.perldoc.com/perl5.6.1/pod/perlre.html">perldoc
'<strong><code>cookie|CO=</code></strong><em>NAME</em>:<em>VAL</em>:<em>domain</em>[:<em>lifetime</em>[:<em>path</em>]]'
^/somepath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
^/somepath(.*) http://thishost/otherpath$1 [P] not supported, because silly!
^localpath(.*) otherpath$1 [R] http://thishost/somepath/otherpath/pathinfo
^localpath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
^localpath(.*) http://thishost/otherpath$1 [P] not supported, because silly!