mod_rewrite.html revision 3dfc894664859f528d379c5f52d6840485219161
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2291faee92ebb5cc9722cd3f22e499900a5a411fvboxsync<!--%hypertext -->
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync<!-- Documentation for the mod_rewrite Apache module -->
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync<!-- Background white, links blue (unvisited), navy (visited), red (active) -->
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync BGCOLOR="#FFFFFF"
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync TEXT="#000000"
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync LINK="#0000FF"
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync VLINK="#000080"
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync ALINK="#FF0000"
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync<!--#include virtual="header.html" -->
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync<H1 ALIGN="CENTER">Module mod_rewrite<BR>URL Rewriting Engine</H1>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncThis module is contained in the <CODE>mod_rewrite.c</CODE> file, with Apache
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync1.2 and later. It provides a rule-based rewriting engine to rewrite requested
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncURLs on the fly. It is not compiled into the server by default. To use
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync<CODE>mod_rewrite</CODE> you have to enable the following line in the server
98fbd1572991ffd43d5e4518608f991317900b28vboxsync<BLOCKQUOTE>
98fbd1572991ffd43d5e4518608f991317900b28vboxsync<BLOCKQUOTE>
98fbd1572991ffd43d5e4518608f991317900b28vboxsync<BLOCKQUOTE>
98fbd1572991ffd43d5e4518608f991317900b28vboxsync<EM>``The great thing about mod_rewrite is it gives you all the
98fbd1572991ffd43d5e4518608f991317900b28vboxsyncconfigurability and flexibility of Sendmail. The downside to
98fbd1572991ffd43d5e4518608f991317900b28vboxsyncmod_rewrite is that it gives you all the configurability and
0475aa54da073c8f950187120725320fa88b6065vboxsyncflexibility of Sendmail.''</EM>
0475aa54da073c8f950187120725320fa88b6065vboxsync-- Brian Behlendorf<BR>
0475aa54da073c8f950187120725320fa88b6065vboxsyncApache Group
98fbd1572991ffd43d5e4518608f991317900b28vboxsync</BLOCKQUOTE>
98fbd1572991ffd43d5e4518608f991317900b28vboxsync</BLOCKQUOTE>
98fbd1572991ffd43d5e4518608f991317900b28vboxsync</BLOCKQUOTE>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync<BLOCKQUOTE>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync<BLOCKQUOTE>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync<BLOCKQUOTE>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncDespite the tons of examples and docs, mod_rewrite
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncis voodoo. Damned cool voodoo, but still voodoo.
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync-- Brian Moore<BR>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncbem@news.cmc.net
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync</BLOCKQUOTE>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync</BLOCKQUOTE>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync</BLOCKQUOTE>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncWelcome to mod_rewrite, the Swiss Army Knife of URL manipulation!
d8c7ce0986da98641328fc161d6db7e78ef119b2vboxsyncThis module uses a rule-based rewriting engine (based on a regular-expression
d8c7ce0986da98641328fc161d6db7e78ef119b2vboxsyncparser) to rewrite requested URLs on the fly. It supports an unlimited number
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncof rules and an unlimited number of attached rule conditions for each rule to
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncprovide a really flexible and powerful URL manipulation mechanism. The URL
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncmanipulations can depend on various tests, for instance server variables,
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncenvironment variables, HTTP headers, time stamps and even external database
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsynclookups in various formats can be used to achieve a really granular URL
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncThis module operates on the full URLs (including the path-info part) both in
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncper-server context (<CODE>httpd.conf</CODE>) and per-directory context
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync(<CODE>.htaccess</CODE>) and even can generate query-string parts on result.
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncThe rewritten result can lead to internal sub-processing, external request
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncredirection or even to an internal proxy throughput.
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncBut all this functionality and flexibility has its drawback: complexity. So
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncdon't expect to understand this module in it's whole in just one day.
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncThis module was invented and originally written in April 1996<BR>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncand gifted exclusively to the The Apache Group in July 1997 by
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync<BLOCKQUOTE>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync<A HREF="http://www.engelschall.com/"><CODE>Ralf S. Engelschall</CODE></A><BR>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync<A HREF="mailto:rse@engelschall.com"><CODE>rse@engelschall.com</CODE></A><BR>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync<A HREF="http://www.engelschall.com/"><CODE>www.engelschall.com</CODE></A>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync</BLOCKQUOTE>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync <LI><A HREF="#InternalRuleset">Ruleset Processing</A>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync <LI><A HREF="#InternalBackRefs">Regex Back-Reference Availability</A>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncThe internal processing of this module is very complex but needs to be
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncexplained once even to the average user to avoid common mistakes and to let
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncyou exploit its full functionality.
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncFirst you have to understand that when Apache processes a HTTP request it does
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncthis in phases. A hook for each of these phases is provided by the Apache API.
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncMod_rewrite uses two of these hooks: the URL-to-filename translation hook
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncwhich is used after the HTTP request was read and before any authorization
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncstarts and the Fixup hook which is triggered after the authorization phases
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncand after the per-directory config files (<CODE>.htaccess</CODE>) where read,
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncbut before the content handler is activated.
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncSo, after a request comes in and Apache has determined the corresponding
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncserver (or virtual server) the rewriting engine start processing of all
d8c7ce0986da98641328fc161d6db7e78ef119b2vboxsyncmod_rewrite directives from the per-server configuration in the
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncURL-to-filename phase. A few steps later when the final data directories are
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncfound, the per-directory configuration directives of mod_rewrite are triggered
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncin the Fixup phase. In both situations mod_rewrite either rewrites URLs to new
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncURLs or to filenames, although there is no obvious distinction between them.
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncThis is a usage of the API which was not intended this way when the API
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncwas designed, but as of Apache 1.x this is the only way mod_rewrite can
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncoperate. To make this point more clear remember the following two points:
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync<LI>The API currently provides only a URL-to-filename hook. Although
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync mod_rewrite rewrites URLs to URLs, URLs to filenames and even
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync filenames to filenames. In Apache 2.0 the two missing hooks
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync will be added to make the processing more clear. But this
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync point has no drawbacks for the user, it is just a fact which
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync should be remembered: Apache does more in the URL-to-filename hook
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync then the API intends for it.
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync<LI>Unbelievably mod_rewrite provides URL manipulations in per-directory
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync context, i.e. within <CODE>.htaccess</CODE> files, although these are
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync reached a very long time after the URLs were translated to filenames (this
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync has to be this way, because <CODE>.htaccess</CODE> files stay in the
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync filesystem, so processing has already been reached this stage of
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync processing). In other words: According to the API phases at this time it
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync is too late for any URL manipulations. To overcome this chicken and egg
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync problem mod_rewrite uses a trick: When you manipulate a URL/filename in
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync per-directory context mod_rewrite first rewrites the filename back to its
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync corresponding URL (which it usually impossible, but see the
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync <CODE>RewriteBase</CODE> directive below for the trick to achieve this)
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync and then initiates a new internal sub-request with the new URL. This leads
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync to a new processing of the API phases from the beginning.
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync Again mod_rewrite tries hard to make this complicated step totally
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync transparent to the user, but you should remember here: While URL
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsync manipulations in per-server context are really fast and efficient,
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync per-directory rewrites are slow and inefficient due to this chicken and
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync egg problem. But on the other hand this is the only way mod_rewrite can
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync provide (locally restricted) URL manipulations to the average user.
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncDon't forget these two points!
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync<H2><A NAME="InternalRuleset">Ruleset Processing</A></H2>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncNow when mod_rewrite is triggered in these two API phases, it reads the
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsyncconfigured rulesets from its configuration structure (which itself was either
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsynccreated on startup for per-server context or while the directory walk of the
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncApache kernel for per-directory context). Then the URL rewriting engine is
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncstarted with the contained ruleset (one or more rules together with their
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncconditions). The operation of the URL rewriting engine itself is exactly the
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncsame for both configuration contexts. Just the final result processing is
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncThe order of rules in the ruleset is important because the rewriting engine
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncprocesses them in a special order. And this order is not very obvious. The
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncrule is this: The rewriting engine loops through the ruleset rule by rule
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync(<CODE>RewriteRule</CODE> directives!) and when a particular rule matched it
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncoptionally loops through existing corresponding conditions
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync(<CODE>RewriteCond</CODE> directives). Because of historical reasons the
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncconditions are given first, the control flow is a little bit winded. See
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncFigure 1 for more details.
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync<STRONG>Figure 1:</STRONG> The control flow through the rewriting ruleset
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncAs you can see, first the URL is matched against the <EM>Pattern</EM> of each
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncrule. When it fails mod_rewrite immediately stops processing this rule and
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsynccontinues with the next rule. If the <EM>Pattern</EM> matched, mod_rewrite
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsynclooks for corresponding rule conditions. If none are present, it just
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsyncsubstitutes the URL with a new value which is constructed from the string
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsync<EM>Substitution</EM> and goes on with its rule-looping. But if conditions But
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncif conditions exists, it starts an inner loop for processing them in order
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncthey are listed. For conditions the logic is different: We don't match a
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncpattern against the current URL. Instead we first create a string
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync<EM>TestString</EM> by expanding variables, back-references, map lookups, etc.
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncand then we try to match <EM>TestPattern</EM> against it. If the pattern
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncdoesn't match, the complete set of conditions and the corresponding rule fails.
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncIf the pattern matches, then the next condition is processed until no more
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsynccondition is available. If all conditions matched processing is continued with
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncthe substitution of the URL with <EM>Substitution</EM>.
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync<H2><A NAME="InternalBackRefs">Regex Back-Reference Availability</A></H2>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncOne important thing here has to be remembered: Whenever you
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncuse parenthesis in <EM>Pattern</EM> or in one of the <EM>TestPattern</EM>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncback-reference are internally created which can be used with the
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncstrings <CODE>$N</CODE> and <CODE>%N</CODE> (see below). And these
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncare available for creating the strings <EM>Substitution</EM> and
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync<EM>TestCond</EM>. Figure 2 shows at which locations the back-references are
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsynctransfered to for expansion.
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsync<STRONG>Figure 2:</STRONG> The back-reference flow through a rule
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsyncWe know, this was a crash course of mod_rewrite's internal processing. But
d8c7ce0986da98641328fc161d6db7e78ef119b2vboxsyncyou will benefit from this knowledge when reading the following documentation
d8c7ce0986da98641328fc161d6db7e78ef119b2vboxsyncof the available directives.
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync<H1><A NAME="Configuration">Configuration Directives</A></H1>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync><STRONG>Syntax:</STRONG></A> <CODE>RewriteEngine</CODE> {<CODE>on,off</CODE>}<BR>
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsync><STRONG>Default:</STRONG></A> <STRONG><CODE>RewriteEngine off</CODE></STRONG><BR>
eabe3981dbb7a74dcfdefec8e8a91aef562447b5vboxsync><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
f26afbf535b588be6d67288372fa3935aba8f38avboxsync HREF="directive-dict.html#Override"
6387ec341a1eb4a4feec63b35149f0842cdc2e6fvboxsync HREF="directive-dict.html#Compatibility"
6387ec341a1eb4a4feec63b35149f0842cdc2e6fvboxsyncThe <CODE>RewriteEngine</CODE> directive enables or disables the runtime
281355d119570e85ac05de0e4ccd2e88cfec3ab7vboxsyncrewriting engine. If it is set to <CODE>off</CODE> this module does no runtime
281355d119570e85ac05de0e4ccd2e88cfec3ab7vboxsyncprocessing at all. It does not even update the <CODE>SCRIPT_URx</CODE>
281355d119570e85ac05de0e4ccd2e88cfec3ab7vboxsyncenvironment variables.
281355d119570e85ac05de0e4ccd2e88cfec3ab7vboxsyncUse this directive to disable the module instead of commenting out
4ac1a1a2774813458198b815ae6bc5a7fa55a8fevboxsyncNote that, by default, rewrite configurations are not inherited.
4ac1a1a2774813458198b815ae6bc5a7fa55a8fevboxsyncThis means that you need to have a <CODE>RewriteEngine on</CODE>
4ac1a1a2774813458198b815ae6bc5a7fa55a8fevboxsyncdirective for each virtual host you wish to use it in.
4ac1a1a2774813458198b815ae6bc5a7fa55a8fevboxsync<H3><A NAME="RewriteOptions">RewriteOptions</A></H3>
0605a093a56d273ac99c885e03812c67b8bcda59vboxsync><STRONG>Syntax:</STRONG></A> <CODE>RewriteOptions</CODE> <EM>Option</EM><BR>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR>
326e463c7c54b7334062bb127880560033c74d1bvboxsync HREF="directive-dict.html#Override"
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync HREF="directive-dict.html#Compatibility"
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncThe <CODE>RewriteOptions</CODE> directive sets some special options for the
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsynccurrent per-server or per-directory configuration. The <EM>Option</EM>
25495f8c2d9e675b44785c59fae20ae178683666vboxsyncstrings can be one of the following:
28f7c365de35f0ff8b8d9d04444f178d13a654devboxsync This forces the current configuration to inherit the configuration of the
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync parent. In per-virtual-server context this means that the maps,
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync conditions and rules of the main server gets inherited. In per-directory
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync context this means that conditions and rules of the parent directory's
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync <CODE>.htaccess</CODE> configuration gets inherited.
d8c7ce0986da98641328fc161d6db7e78ef119b2vboxsync><STRONG>Syntax:</STRONG></A> <CODE>RewriteLog</CODE> <EM>Filename</EM><BR>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync><STRONG>Context:</STRONG></A> server config, virtual host<BR>
25495f8c2d9e675b44785c59fae20ae178683666vboxsync HREF="directive-dict.html#Override"
da8ffadfe0ce4fe0b0ea41f0ce5136936f3ad7e3vboxsync><STRONG>Override:</STRONG></A> <EM>Not applicable</EM><BR>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync HREF="directive-dict.html#Compatibility"
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncThe <CODE>RewriteLog</CODE> directive sets the name of the file to which the
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncserver logs any rewriting actions it performs. If the name does not begin
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncwith a slash ('<CODE>/</CODE>') then it is assumed to be relative to the
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync<EM>Server Root</EM>. The directive should occur only once per server
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsync<TABLE WIDTH="70%" BORDER=0 BGCOLOR="#E0E0F0" CELLSPACING=0 CELLPADDING=10>
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsync<STRONG>Notice</STRONG>: To disable the logging of rewriting actions it is not recommended
d8c7ce0986da98641328fc161d6db7e78ef119b2vboxsyncto <CODE>/dev/null</CODE>, because although the rewriting engine does
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsyncnot create output to a logfile it still creates the logfile
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsyncoutput internally. <STRONG>This will slow down the server with no advantage to the
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsyncadministrator!</STRONG>
d8c7ce0986da98641328fc161d6db7e78ef119b2vboxsyncTo disable logging either remove or comment out the
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsync<CODE>RewriteLog</CODE> directive or use <CODE>RewriteLogLevel 0</CODE>!
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsync<TABLE WIDTH="70%" BORDER=0 BGCOLOR="#E0E0F0" CELLSPACING=0 CELLPADDING=10>
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsyncHREF="/misc/security_tips.html">Apache Security
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsyncTips</A> document for details on why your security could be compromised if the
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsyncdirectory where logfiles are stored is writable by anyone other than the user
d7355434760f5830da16f763401569d7c0a503e5vboxsyncthat starts the server.
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsync<BLOCKQUOTE>
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsync</BLOCKQUOTE>
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsync<H3><A NAME="RewriteLogLevel">RewriteLogLevel</A></H3>
d8c7ce0986da98641328fc161d6db7e78ef119b2vboxsync><STRONG>Syntax:</STRONG></A> <CODE>RewriteLogLevel</CODE> <EM>Level</EM><BR>
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsync><STRONG>Default:</STRONG></A> <STRONG><CODE>RewriteLogLevel 0</CODE></STRONG><BR>
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsync><STRONG>Context:</STRONG></A> server config, virtual host<BR>
0605a093a56d273ac99c885e03812c67b8bcda59vboxsync HREF="directive-dict.html#Override"
a1e70139605e98f1fa3d8463f2d406186b282436vboxsync><STRONG>Override:</STRONG></A> <EM>Not applicable</EM><BR>
0605a093a56d273ac99c885e03812c67b8bcda59vboxsync HREF="directive-dict.html#Compatibility"
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsyncThe <CODE>RewriteLogLevel</CODE> directive set the verbosity level of the rewriting
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsynclogfile. The default level 0 means no logging, while 9 or more means
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsyncthat practically all actions are logged.
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsyncTo disable the logging of rewriting actions simply set <EM>Level</EM> to 0.
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsyncThis disables all rewrite action logs.
b8923cb58f1729ccea5d285d79541c884aa3a811vboxsync<TABLE WIDTH="70%" BORDER=0 BGCOLOR="#E0E0F0" CELLSPACING=0 CELLPADDING=10>
f69c3d4a91f0dad655cfc08ab4e6ca50475d9f99vboxsync<STRONG>Notice:</STRONG> Using a high value for <EM>Level</EM> will slow down your Apache
f69c3d4a91f0dad655cfc08ab4e6ca50475d9f99vboxsyncserver dramatically! Use the rewriting logfile only for debugging or at least
a3c492dd6618e57dadb06df04c55848f8f500073vboxsync<BLOCKQUOTE>
a3c492dd6618e57dadb06df04c55848f8f500073vboxsyncRewriteLogLevel 3
a3c492dd6618e57dadb06df04c55848f8f500073vboxsync</BLOCKQUOTE>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync><STRONG>Syntax:</STRONG></A> <CODE>RewriteLock</CODE> <EM>Filename</EM><BR>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync><STRONG>Context:</STRONG></A> server config, virtual host<BR>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync HREF="directive-dict.html#Override"
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync><STRONG>Override:</STRONG></A> <EM>Not applicable</EM><BR>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync HREF="directive-dict.html#Compatibility"
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncThis directive sets the filename for a synchronization lockfile which
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncmod_rewrite needs to communicate with <SAMP>RewriteMap</SAMP>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync<EM>programs</EM>. Set this lockfile to a local path (not on a NFS-mounted
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncdevice) when you want to use a rewriting map-program. It is not required for
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncSAMP using all other types of rewriting maps.
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsync><STRONG>Syntax:</STRONG></A> <CODE>RewriteMap</CODE> <EM>MapName</EM> <EM>MapType</EM><CODE>:</CODE><EM>MapSource</EM><BR>
d84e68ca765cf126f11e0d8533dde87b252288bcvboxsync><STRONG>Default:</STRONG></A> not used per default<BR>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync><STRONG>Context:</STRONG></A> server config, virtual host<BR>
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsync HREF="directive-dict.html#Override"
da8ffadfe0ce4fe0b0ea41f0ce5136936f3ad7e3vboxsync><STRONG>Override:</STRONG></A> <EM>Not applicable</EM><BR>
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsync HREF="directive-dict.html#Compatibility"
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsync><STRONG>Compatibility:</STRONG></A> Apache 1.2 (partially), Apache 1.3<BR>
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsyncThe <CODE>RewriteMap</CODE> directive defines a <EM>Rewriting Map</EM>
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsyncwhich can be used inside rule substitution strings by the mapping-functions
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsyncto insert/substitute fields through a key lookup. The source of this
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsynclookup can be of various types.
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsyncThe <A NAME="mapfunc"><EM>MapName</EM></A> is the name of the map and will
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsyncbe used to specify a mapping-function for the substitution strings of a
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsyncrewriting rule via one of the following constructs:
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsync<CODE>${</CODE> <EM>MapName</EM> <CODE>:</CODE> <EM>LookupKey</EM>
c55cc72bb3e004a4bf056356731a85b283ceadc8vboxsync<CODE>${</CODE> <EM>MapName</EM> <CODE>:</CODE> <EM>LookupKey</EM>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncWhen such a construct occurs the map <EM>MapName</EM>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncis consulted and the key <EM>LookupKey</EM> is looked-up. If the key is
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncfound, the map-function construct is substituted by <EM>SubstValue</EM>. If
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncthe key is not found then it is substituted by <EM>DefaultValue</EM> or
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncthe empty string if no <EM>DefaultValue</EM> was specified.
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncThe following combinations for <EM>MapType</EM> and <EM>MapSource</EM>
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsynccan be used:
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync MapType: <CODE>txt</CODE>, MapSource: Unix filesystem path to valid regular file
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync This is the standard rewriting map feature where the <EM>MapSource</EM> is
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync a plain ASCII file containing either blank lines, comment lines (starting
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync with a '#' character) or pairs like the following - one per line.
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=5 BGCOLOR="#F0F0F0">
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync## map.txt -- rewriting map
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncRalf.S.Engelschall rse # Bastard Operator From Hell
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsyncMr.Joe.Average joe # Mr. Average
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=5 BGCOLOR="#F0F0F0">
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync MapType: <CODE>rnd</CODE>, MapSource: Unix filesystem path to valid regular file
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync This is identical to the Standard Plain Text variant above but with a special
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync post-processing feature: After looking up a value it is parsed according
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync to contained ``<CODE>|</CODE>'' characters which have the meaning of ``or''. Or
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync in other words: they indicate a set of alternatives from which the actual
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync returned value is chosen randomly. Although this sounds crazy and useless, it
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync was actually designed for load balancing in a reverse proxy situation where
e4f4db78380dcf0d83ef71a38ecab7b25fe9ecc2vboxsync the looked up values are server names.
## map.txt -- rewriting map
executable (i.e. either object-code or a script with the
(i.e. key == value) could be:
# ...here any transformations
HREF="directive-dict.html#Syntax"
HREF="directive-dict.html#Default"
HREF="directive-dict.html#Context"
HREF="directive-dict.html#Override"
HREF="directive-dict.html#Status"
HREF="directive-dict.html#Module"
HREF="directive-dict.html#Compatibility"
locally, i.e. the local directory prefix is stripped at this stage of
RewriteRule ^oldstuff\.html$ newstuff.html
HREF="directive-dict.html#Syntax"
HREF="directive-dict.html#Default"
HREF="directive-dict.html#Context"
HREF="directive-dict.html#Override"
HREF="directive-dict.html#Status"
HREF="directive-dict.html#Module"
HREF="directive-dict.html#Compatibility"
This makes the condition test case-insensitive, i.e. there is
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="directive-dict.html#Syntax"
HREF="directive-dict.html#Default"
HREF="directive-dict.html#Context"
HREF="directive-dict.html#Override"
HREF="directive-dict.html#Status"
HREF="directive-dict.html#Module"
HREF="directive-dict.html#Compatibility"
<LI>'<STRONG><CODE>redirect|R</CODE> [=<EM>code</EM>]</STRONG>' (force <A NAME="redirect"><STRONG>r</STRONG>edirect</A>)<BR>
canonicalize the URL and gives it back to the client, e.g. translate
This forces the current URL to be forbidden, i.e. it immediately sends
This forces the current URL to be gone, i.e. it immediately sends back a
request and immediately (i.e. rewriting rule processing stops here) put
sure that the substitution string is a valid URI (e.g. typically starting
language. Use this flag to restart the rewriting process, i.e. to
effect: if a rule matches, then processing continues as usual, i.e. the
<LI>'<STRONG><CODE>type|T</CODE></STRONG>=<EM>mime-type</EM>' (force MIME <STRONG>t</STRONG>ype)<BR>
<LI>'<STRONG><CODE>nosubreq|NS</CODE></STRONG>' (used only if <STRONG>n</STRONG>o internal <STRONG>s</STRONG>ub-request)<BR>
<LI>'<STRONG><CODE>passthrough|PT</CODE></STRONG>' (<STRONG>p</STRONG>ass <STRONG>t</STRONG>hrough to next handler)<BR>
<LI>'<STRONG><CODE>env|E=</CODE></STRONG><EM>VAR</EM>:<EM>VAL</EM>' (set <STRONG>e</STRONG>nvironment variable)<BR>
^/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!
SCRIPT_URI=http://en1.engelschall.com/u/rse/
<!--#include virtual="footer.html" -->