mod_rewrite.html revision 2ffb212453e05772aaf30a1b8bf8ea6472048fbc
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<!--%hypertext -->
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<!-- mod_rewrite.html -->
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<!-- Documentation for the mod_rewrite Apache module -->
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<HTML>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<HEAD>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TITLE>Apache module mod_rewrite</TITLE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</HEAD>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<!-- Background white, links blue (unvisited), navy (visited), red (active) -->
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<BODY
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync BGCOLOR="#FFFFFF"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync TEXT="#000000"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync LINK="#0000FF"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync VLINK="#000080"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync ALINK="#FF0000"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<!--#include virtual="header.html" -->
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<H1 ALIGN="CENTER">Module mod_rewrite<BR>URL Rewriting Engine</H1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncThis module is contained in the <CODE>mod_rewrite.c</CODE> file, with Apache
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync1.2 and later. It provides a rule-based rewriting engine to rewrite requested
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncURLs on the fly. It is not compiled into the server by default. To use
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<CODE>mod_rewrite</CODE> you have to enable the following line in the server
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncbuild <CODE>Configuration</CODE> file:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<PRE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync AddModule modules/standard/mod_rewrite.o
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</PRE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<HR NOSHADE SIZE=1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<H2>Summary</H2>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<EM>,,The great thing about mod_rewrite is it gives you all the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncconfigurability and flexibility of Sendmail. The downside to
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncmod_rewrite is that it gives you all the configurability and
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncflexibility of Sendmail.''</EM>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<DIV ALIGN=RIGHT>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync-- Brian Behlendorf<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncApache Group
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</DIV>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncWelcome to mod_rewrite, the Swiss Army Knife of URL manipulation!
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncThis module uses a rule-based rewriting engine (based on a regular-expression
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncparser) to rewrite requested URLs on the fly. It supports an unlimited number
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncof rules and an unlimited number of attached rule conditions for each rule to
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncprovide a really flexible and powerful URL manipulation mechanism. The URL
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncmanipulations can depend on various tests, for instance server variables,
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncenvironment variables, HTTP headers, timestamps and even external database
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynclookups in various formats can be used to achieve a really granular URL
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncmatching.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncThis module operates on the full URLs (including the path-info part) both in
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncper-server context (<CODE>httpd.conf</CODE>) and per-directory context
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync(<CODE>.htaccess</CODE>) and even can generate query-string parts on result.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncThe rewritten result can lead to internal sub-processing, external request
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncredirection or even to an internal proxy throughput.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncBut all this functionality and flexibility has its drawback: complexity. So
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncdon't expect to understand this module in it's whole in just one day.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncThis module was invented and originally written in April 1996<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncand gifted exclusively to the The Apache Group in July 1997 by
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <A HREF="http://www.engelschall.com/"><TT>Ralf S. Engelschall</TT></A><BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <A HREF="mailto:rse@engelschall.com"><TT>rse@engelschall.com</TT></A><BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <A HREF="http://www.engelschall.com/"><TT>www.engelschall.com</TT></A>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<HR NOSHADE SIZE=1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<H2>Table Of Contents</H2>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>Internal Processing</STRONG>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<UL>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <LI><A HREF="#InternalAPI">API Phases</A>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <LI><A HREF="#InternalRuleset">Ruleset Processing</A>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <LI><A HREF="#InternalBackRefs">Regex Back-Reference Availability</A>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</UL>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>Configuration Directives</STRONG>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<UL>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <LI><A HREF="#RewriteEngine">RewriteEngine</A>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <LI><A HREF="#RewriteOptions">RewriteOptions</A>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <LI><A HREF="#RewriteLog">RewriteLog</A>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <LI><A HREF="#RewriteLogLevel">RewriteLogLevel</A>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <LI><A HREF="#RewriteLock">RewriteLock</A>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <LI><A HREF="#RewriteMap">RewriteMap</A>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <LI><A HREF="#RewriteBase">RewriteBase</A>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <LI><A HREF="#RewriteCond">RewriteCond</A>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <LI><A HREF="#RewriteRule">RewriteRule</A>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</UL>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>Miscellaneous</STRONG>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<UL>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <LI><A HREF="#EnvVar">Environment Variables</A>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <LI><A HREF="#Solutions">Practical Solutions</A>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</UL>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<HR NOSHADE SIZE=1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<CENTER>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<H1><A NAME="Internal">Internal Processing</A></H1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</CENTER>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<HR NOSHADE SIZE=1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncThe internal processing of this module is very complex but needs to be
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncexplained once even to the average user to avoid common mistakes and to let
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncyou exploit its full funtionality.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<H2><A NAME="InternalAPI">API Phases</A></H2>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncFirst you have to understand that when Apache processes a HTTP request it does
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncthis in phases. A hook for each of these phases is provided by the Apache API.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncMod_rewrite uses two of these hooks: the URL-to-filename translation hook
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncwhich is used after the HTTP request was read and before any authorization
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncstarts and the Fixup hook which is triggered after the authorization phases
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncand after the per-directory config files (<CODE>.htaccess</CODE>) where read,
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncbut before the content handler is activated.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncSo, after a request comes in and Apache has determined the corresponding
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncserver (or virtual server) the rewriting engine start processing of all
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncmod_rewrite directives from the per-server configuration in the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncURL-to-filename phase. A few steps later when the final data directories are
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncfound, the per-directory configuration directives of mod_rewrite are triggered
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncin the Fixup phase. In both situations mod_rewrite either rewrites URLs to new
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncURLs or to filenames, although there is no obvious distinction between them.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncThis is a usage of the API which was not intended this way when the API
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncwas designed, but as of Apache 1.x this is the only way mod_rewrite can
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncoperate. To make this point more clear remember the following two points:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<OL>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>The API currently provides only a URL-to-filename hook. Although
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync mod_rewrite rewrites URLs to URLs, URLs to filenames and even
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync filenames to filenames. In Apache 2.0 the two missing hooks
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync will be added to make the processing more clear. But this
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync point has no drawbacks for the user, it is just a fact which
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync should be remembered: Apache does more in the URL-to-filename hook
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync then the API intends for it.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>Unbelievably mod_rewrite provides URL manipulations in per-directory
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync context, i.e. within <CODE>.htaccess</CODE> files, although these are
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync reached a very long time after the URLs were translated to filenames (this
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync has to be this way, because <CODE>.htaccess</CODE> files stay in the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync filesystem, so processing has already been reached this stage of
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync processing). In other words: According to the API phases at this time it
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync is too late for any URL manipulations. To overcome this chicken and egg
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync problem mod_rewrite uses a trick: When you manipulate a URL/filename in
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync per-directory context mod_rewrite first rewrites the filename back to its
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync corresponding URL (which it usually impossible, but see the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <CODE>RewriteBase</CODE> directive below for the trick to achieve this)
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync and then initiates a new internal sub-request with the new URL. This leads
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync to a new processing of the API phases from the beginning.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync Again mod_rewrite tries hard to make this complicated step totally
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync transparent to the user, but you should remember here: While URL
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync manipulations in per-server context are really fast and efficient,
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync per-directory rewrites are slow and inefficient due to this chicken and
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync egg problem. But on the other hand this is the only way mod_rewrite can
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync provide (locally restricted) URL manipulatiuons to the avarage user.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</OL>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncDon't forget these two points!
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<H2><A NAME="InternalRuleset">Ruleset Processing</A></H2>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncNow when mod_rewrite is triggered in these two API phases, it reads the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncconfigured rulesets from its configuration structure (which itself was either
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynccreated on startup for per-server context or while the directory walk of the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncApache kernel for per-directory context). Then the URL rewriting engine is
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncstarted with the contained ruleset (one or more rules together with their
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncconditions). The operation of the URL rewriting engine itself is exactly the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncsame for both configuration contexts. Just the final result processing is
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncdifferent.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncThe order of rules in the ruleset is important because the rewriting engine
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncprocesses them in a special order. And this order is not very obvious. The
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncrule is this: The rewriting engine loops through the ruleset rule by rule
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync(<CODE>RewriteRule</CODE> directives!) and when a particular rule matched it
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncoptionally loops through existing corresponding conditions
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync(<CODE>RewriteCond</CODE> directives). Because of historical reasons the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncconditions are given first, the control flow is a little bit winded. See
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncFigure 1 for more details.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<DIV ALIGN=CENTER>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<table cellspacing=0 cellpadding=2 border=0>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<tr>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<td bgcolor="#cccccc"><img src="/images/mod_rewrite_fig1.gif"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync alt="[Needs graphics capability to display]"></td>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</tr>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<tr>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<td align=center>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<strong>Figure 1:</strong> The control flow through the rewriting ruleset
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</td>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</tr>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</table>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</DIV>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncAs you can see, first the URL is matched against the <EM>Pattern</EM> of each
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncrule. When it fails mod_rewrite immediately stops processing this rule and
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynccontinues with the next rule. If the <EM>Pattern</EM> matched, mod_rewrite
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynclooks for corresponding rule conditions. If none are present, it just
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncsubstitutes the URL with a new value which is constructed from the string
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<EM>Substitution</EM> and goes on with its rule-looping. But if conditions But
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncif conditions exists, it starts an inner loop for processing them in order
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncthey are listed. For conditions the logic is different: We don't match a
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncpattern against the current URL. Instead we first create a string
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<EM>TestString</EM> by expanding variables, back-references, map lookups, etc.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncand then we try to match <EM>TestPattern</EM> against it. If the pattern
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncdoesn't match, the complete set of conditions and the corresponding rule fails.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncIf the pattern matches, then the next condition is processed until no more
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynccondition is available. If all conditions matched processing is continued with
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncthe substitution of the URL with <EM>Substitution</EM>.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<H2><A NAME="InternalBackRefs">Regex Back-Reference Availability</A></H2>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncOne important thing here has to be rememberd: Whenever you
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncuse parenthesis in <EM>Pattern</EM> or in one of the <EM>TestPattern</EM>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncback-reference are internally created which can be used with the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncstrings <CODE>$N</CODE> and <CODE>%N</CODE> (see below). And these
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncare available for creating the strings <EM>Substitution</EM> and
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<EM>TestCond</EM>. Figure 2 shows at which locations the back-references are
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynctransfered to for expansion.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<DIV ALIGN=CENTER>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<table cellspacing=0 cellpadding=2 border=0>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<tr>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<td bgcolor="#cccccc"><img src="/images/mod_rewrite_fig2.gif"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync alt="[Needs graphics capability to display]"></td>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</tr>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<tr>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<td align=center>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<strong>Figure 2:</strong> The back-reference flow through a rule
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</td>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</tr>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</table>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</DIV>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncWe know, this was a crash course of mod_rewrite's internal processing. But
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncyou will benefit from this knowledge when reading the following documentation
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncof the available directives.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<HR NOSHADE SIZE=1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<CENTER>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<H1><A NAME="Configuration">Configuration Directives</A></H1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</CENTER>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<HR NOSHADE SIZE=1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<H3><A NAME="RewriteEngine">RewriteEngine</A></H3>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<A
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync HREF="directive-dict.html#Syntax"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync REL="Help"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync><STRONG>Syntax:</STRONG></A> <CODE>RewriteEngine</CODE> {<CODE>on,off</CODE>}<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<A
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync HREF="directive-dict.html#Default"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync REL="Help"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync><STRONG>Default:</STRONG></A> <STRONG><CODE>RewriteEngine off</CODE></STRONG><BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<A
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync HREF="directive-dict.html#Context"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync REL="Help"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync><STRONG>Context:</STRONG></A> server config, virtual host, per-directory config<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncThe <TT>RewriteEngine</TT> directive enables or disables the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncruntime rewriting engine. If it is set to <CODE>off</CODE> this module does
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncno runtime processing at all. It does not even update the <TT>SCRIPT_URx</TT>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncenvironment variables.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncUse this directive to disable the module instead of commenting out
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncall <TT>RewriteRule</TT> directives!
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncNote that, by default, rewrite configurations are not inherited.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncThis means that you need to have a <TT>RewriteEngine on</TT>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncdirective for each virtual host you wish to use it in.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<hr noshade size=1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<H3><A NAME="RewriteOptions">RewriteOptions</A></H3>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<A
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync HREF="directive-dict.html#Syntax"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync REL="Help"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync><STRONG>Syntax:</STRONG></A> <CODE>RewriteOptions</CODE> <EM>Option</EM> ...<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<A
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync HREF="directive-dict.html#Default"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync REL="Help"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync><STRONG>Default:</STRONG></A> -<EM>None</EM>-<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<A
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync HREF="directive-dict.html#Context"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync REL="Help"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync><STRONG>Context:</STRONG></A> server config, virtual host, per-directory config<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncThe <TT>RewriteOptions</TT> directive sets some special options for the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynccurrent per-server or per-directory configuration. The <EM>Option</EM>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncstrings can be one of the following:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<UL>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>'<STRONG><CODE>inherit</CODE></STRONG>'<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync This forces the current configuration to inherit the configuration of the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync parent. In per-virtual-server context this means that the maps,
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync conditions and rules of the main server gets inherited. In per-directory
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync context this means that conditions and rules of the parent directory's
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <TT>.htaccess</TT> configuration gets inherited.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</UL>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<hr noshade size=1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<H3><A NAME="RewriteLog">RewriteLog</A></H3>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<A
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync HREF="directive-dict.html#Syntax"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync REL="Help"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync><STRONG>Syntax:</STRONG></A> <CODE>RewriteLog</CODE> <EM>Filename</EM><BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<A
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync HREF="directive-dict.html#Default"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync REL="Help"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync><STRONG>Default:</STRONG></A> -<EM>None</EM>-<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<A
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync HREF="directive-dict.html#Context"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync REL="Help"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync><STRONG>Context:</STRONG></A> server config, virtual host<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncThe <TT>RewriteLog</TT> directive sets the name of the file to which the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncserver logs any rewriting actions it performs. If the name does not begin
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncwith a slash ('<TT>/</TT>') then it is assumed to be relative to the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<EM>Server Root</EM>. The directive should occur only once per server
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncconfig.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<table width="70%" border=0 bgcolor="#e0e0f0" cellspacing=0 cellpadding=10>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TR><TD>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>Notice</STRONG>: To disable the logging of rewriting actions it is not recommended
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncto set <EM>Filename</EM>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncto <CODE>/dev/null</CODE>, because although the rewriting engine does
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncnot create output to a logfile it still creates the logfile
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncoutput internally. <STRONG>This will slow down the server with no advantage to the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncadministrator!</STRONG>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncTo disable logging either remove or comment out the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TT>RewriteLog</TT> directive or use <TT>RewriteLogLevel 0</TT>!
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TD></TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TABLE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<table width="70%" border=0 bgcolor="#e0e0f0" cellspacing=0 cellpadding=10>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TR><TD>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>Security</STRONG>: See the <A
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncHREF="/misc/security_tips.html">Apache Security
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncTips</A> document for details on why your security could be compromised if the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncdirectory where logfiles are stored is writable by anyone other than the user
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncthat starts the server.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TD></TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TABLE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>Example:</STRONG>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<PRE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncRewriteLog "/usr/local/var/apache/logs/rewrite.log"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</PRE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<hr noshade size=1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<H3><A NAME="RewriteLogLevel">RewriteLogLevel</A></H3>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<A
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync HREF="directive-dict.html#Syntax"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync REL="Help"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync><STRONG>Syntax:</STRONG></A> <CODE>RewriteLogLevel</CODE> <EM>Level</EM><BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<A
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync HREF="directive-dict.html#Default"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync REL="Help"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync><STRONG>Default:</STRONG></A> <STRONG><CODE>RewriteLogLevel 0</CODE></STRONG><BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<A
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync HREF="directive-dict.html#Context"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync REL="Help"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync><STRONG>Context:</STRONG></A> server config, virtual host<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncThe <TT>RewriteLogLevel</TT> directive set the verbosity level of the rewriting
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynclogfile. The default level 0 means no logging, while 9 or more means
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncthat practically all actions are logged.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncTo disable the logging of rewriting actions simply set <EM>Level</EM> to 0.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncThis disables all rewrite action logs.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<table width="70%" border=0 bgcolor="#e0e0f0" cellspacing=0 cellpadding=10>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TR><TD>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>Notice:</STRONG> Using a high value for <EM>Level</EM> will slow down your Apache
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncserver dramatically! Use the rewriting logfile only for debugging or at least
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncat <EM>Level</EM> not greater than 2!
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TD></TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TABLE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>Example:</STRONG>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<PRE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncRewriteLogLevel 3
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</PRE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<hr noshade size=1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<H3><A NAME="RewriteLock">RewriteLock</A></H3>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<A
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync HREF="directive-dict.html#Syntax"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync REL="Help"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync><STRONG>Syntax:</STRONG></A> <CODE>RewriteLock</CODE> <EM>Filename</EM><BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<A
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync HREF="directive-dict.html#Default"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync REL="Help"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync><STRONG>Default:</STRONG></A> -<EM>None</EM>-<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<A
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync HREF="directive-dict.html#Context"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync REL="Help"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync><STRONG>Context:</STRONG></A> server config, virtual host<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncThis directive sets the filename for a synchronization lockfile which
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncmod_rewrite needs to communicate with <SAMP>RewriteMap</SAMP>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<EM>programs</EM>. Set this lockfile to a local path (not on a NFS-mounted
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncdevice) when you want to use a rewriting map-program. It is not required for
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncSAMP
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncusing all other types of rewriting maps.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<hr noshade size=1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<H3><A NAME="RewriteMap">RewriteMap</A></H3>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<A
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync HREF="directive-dict.html#Syntax"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync REL="Help"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync><STRONG>Syntax:</STRONG></A> <CODE>RewriteMap</CODE> <EM>MapName</EM> <EM>MapType</EM><CODE>:</CODE><EM>MapSource</EM><BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<A
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync HREF="directive-dict.html#Default"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync REL="Help"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync><STRONG>Default:</STRONG></A> not used per default<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<A
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync HREF="directive-dict.html#Context"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync REL="Help"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync><STRONG>Context:</STRONG></A> server config, virtual host<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncThe <TT>RewriteMap</TT> directive defines a <EM>Rewriting Map</EM>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncwhich can be used inside rule substitution strings by the mapping-functions
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncto insert/substitute fields through a key lookup. The source of this
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynclookup can be of various types.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncThe <A NAME="mapfunc"><EM>MapName</EM></A> is the name of the map and will
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncbe used to specify a mapping-function for the substitution strings of a
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncrewriting rule via one of the following constructs:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<BLOCKQUOTE><STRONG>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<CODE>${</CODE> <EM>MapName</EM> <CODE>:</CODE> <EM>LookupKey</EM>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<CODE>}</CODE><BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<CODE>${</CODE> <EM>MapName</EM> <CODE>:</CODE> <EM>LookupKey</EM>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<CODE>|</CODE> <EM>DefaultValue</EM> <CODE>}</CODE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</STRONG></BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncWhen such a construct occurs the map <EM>MapName</EM>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncis consulted and the key <EM>LookupKey</EM> is looked-up. If the key is
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncfound, the map-function construct is substituted by <EM>SubstValue</EM>. If
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncthe key is not found then it is substituted by <EM>DefaultValue</EM> or
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncthe empty string if no <EM>DefaultValue</EM> was specified.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncThe following combinations for <EM>MapType</EM> and <EM>MapSource</EM>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynccan be used:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<UL>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI><STRONG>Standard Plain Text</STRONG><BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync MapType: <CODE>txt</CODE>, MapSource: Unix filesystem path to valid regular file
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync This is the standard rewriting map feature where the <EM>MapSource</EM> is
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync a plain ASCII file containing either blank lines, comment lines (starting
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync with a '#' character) or pairs like the following - one per line.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <BLOCKQUOTE><STRONG>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <EM>MatchingKey</EM> <EM>SubstValue</EM>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </STRONG></BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync Example:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<table border=0 cellspacing=1 cellpadding=5 bgcolor="#f0f0f0">
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TR><TD><PRE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync##
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync## map.txt -- rewriting map
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync##
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncRalf.S.Engelschall rse # Bastard Operator From Hell
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncMr.Joe.Average joe # Mr. Average
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</PRE></TD></TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TABLE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<table border=0 cellspacing=1 cellpadding=5 bgcolor="#f0f0f0">
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TR><TD><PRE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncRewriteMap real-to-host txt:/path/to/file/map.txt
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</PRE></TD></TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TABLE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI><STRONG>Randomized Plain Text</STRONG><BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync MapType: <CODE>rnd</CODE>, MapSource: Unix filesystem path to valid regular file
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync This is identical to the Standard Plain Text variant above but with a special
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync post-processing feature: After looking up a value it is parsed according
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync to contained ``<TT>|</TT>'' characters which have the meaning of ``or''. Or
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync in other words: they indicate a set of alternatives from which the actual
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync returned value is choosen randomly. Although this sounds crazy and useless, it
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync was actually designed for load balancing in a reverse proxy situation where
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync the looked up values are server names.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync Example:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<table border=0 cellspacing=1 cellpadding=5 bgcolor="#f0f0f0">
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TR><TD><PRE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync##
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync## map.txt -- rewriting map
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync##
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncstatic www1|www2|www3|www4
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncdynamic www5|www6
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</PRE></TD></TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TABLE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<table border=0 cellspacing=1 cellpadding=5 bgcolor="#f0f0f0">
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TR><TD><PRE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncRewriteMap servers rnd:/path/to/file/map.txt
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</PRE></TD></TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TABLE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI><STRONG>Hash File</STRONG><BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync MapType: <CODE>dbm</CODE>, MapSource: Unix filesystem path to valid regular file
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync Here the source is a binary NDBM format file containing the same contents
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync as a <EM>Plain Text</EM> format file, but in a special representation
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync which is optimized for really fast lookups. You can create such a file with
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync any NDBM tool or with the following Perl script:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <table border=0 cellspacing=1 cellpadding=5 bgcolor="#f0f0f0">
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <TR><TD><PRE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync#!/path/to/bin/perl
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync##
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync## txt2dbm -- convert txt map to dbm format
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync##
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync($txtmap, $dbmmap) = @ARGV;
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncopen(TXT, "&lt;$txtmap");
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncdbmopen(%DB, $dbmmap, 0644);
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncwhile (&lt;TXT&gt;) {
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync next if (m|^s*#.*| or m|^s*$|);
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync $DB{$1} = $2 if (m|^\s*(\S+)\s+(\S+)$|);
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync}
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncdbmclose(%DB);
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncclose(TXT)</PRE></TD></TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </TABLE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <table border=0 cellspacing=1 cellpadding=5 bgcolor="#f0f0f0">
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <TR><TD><PRE>$ txt2dbm map.txt map.db </PRE></TD></TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </TABLE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI><STRONG>Internal Function</STRONG><BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync MapType: <CODE>int</CODE>, MapSource: Internal Apache function
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync Here the source is an internal Apache function. Currently you cannot
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync create your own, but the following functions already exists:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <UL>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <LI><STRONG>toupper</STRONG>:<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync Converts the looked up key to all upper case.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <LI><STRONG>tolower</STRONG>:<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync Converts the looked up key to all lower case.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </UL>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI><STRONG>External Rewriting Program</STRONG><BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync MapType: <CODE>prg</CODE>, MapSource: Unix filesystem path to valid regular file
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync Here the source is a Unix program, not a map file. To create it you can use
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync the language of your choice, but the result has to be a run-able Unix
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync executable (i.e. either object-code or a script with the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync magic cookie trick '<TT>#!/path/to/interpreter</TT>' as the first line).
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync This program gets started once at startup of the Apache servers and then
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync communicates with the rewriting engine over its <TT>stdin</TT> and
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <TT>stdout</TT> file-handles. For each map-function lookup it will
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync receive the key to lookup as a newline-terminated string on
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <TT>stdin</TT>. It then has to give back the looked-up value as a
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync newline-terminated string on <TT>stdout</TT> or the four-character string
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync ``<TT>NULL</TT>'' if it fails (i.e. there is no corresponding value
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync for the given key). A trivial program which will implement a 1:1 map
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync (i.e. key == value) could be:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<table border=0 cellspacing=1 cellpadding=5 bgcolor="#f0f0f0">
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TR><TD><PRE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync#!/usr/bin/perl
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync$| = 1;
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncwhile (&lt;STDIN&gt;) {
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync # ...here any transformations
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync # or lookups should occur...
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync print $_;
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync}
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</PRE></TD></TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TABLE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync But be very careful:<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <OL>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <LI>``<EM>Keep the program simple, stupid</EM>'' (KISS), because
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync if this program hangs it will lead to a hang of the Apache server
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync when the rule occurs.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <LI>Avoid one common mistake: never do buffered I/O on <TT>stdout</TT>!
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync This will cause a deadloop! Hence the ``<TT>$|=1</TT>'' in the above
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync example...
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <LI>Use the <SAMP>RewriteLock</SAMP> directive to define a lockfile
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync mod_rewrite can use to synchronize the communication to the program.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync Per default no such synchronization takes place.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </OL>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</UL>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncThe <TT>RewriteMap</TT> directive can occur more than once. For each
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncmapping-function use one <TT>RewriteMap</TT> directive to declare its
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncrewriting mapfile. While you cannot <STRONG>declare</STRONG> a map in per-directory
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynccontext it is of course possible to <STRONG>use</STRONG> this map in per-directory
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynccontext.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<table width="70%" border=0 bgcolor="#e0e0f0" cellspacing=0 cellpadding=10>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TR><TD>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>Notice:</STRONG> For plain text and DBM format files the looked-up keys are cached in-core
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncuntil the <TT>mtime</TT> of the mapfile changes or the server does a
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncrestart. This way you can have map-functions in rules which are used
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncfor <STRONG>every</STRONG> request. This is no problem, because the external lookup
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynconly happens once!
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TD></TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TABLE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<hr noshade size=1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<H3><A NAME="RewriteBase">RewriteBase</A></H3>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<A
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync HREF="directive-dict.html#Syntax"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync REL="Help"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync><STRONG>Syntax:</STRONG></A> <CODE>RewriteBase</CODE> <EM>BaseURL</EM><BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<A
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync HREF="directive-dict.html#Default"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync REL="Help"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync><STRONG>Default:</STRONG></A> <EM>default is the physical directory path</EM><BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<A
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync HREF="directive-dict.html#Context"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync REL="Help"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync><STRONG>Context:</STRONG></A> per-directory config<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncThe <TT>RewriteBase</TT> directive explicitly sets the base URL for
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncper-directory rewrites. As you will see below, <TT>RewriteRule</TT> can be
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncused in per-directory config files (<TT>.htaccess</TT>). There it will act
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynclocally, i.e. the local directory prefix is stripped at this stage of
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncprocessing and your rewriting rules act only on the remainder. At the end
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncit is automatically added.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncWhen a substitution occurs for a new URL, this module has to
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncre-inject the URL into the server processing. To be able to do this it needs
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncto know what the corresponding URL-prefix or URL-base is. By default this
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncprefix is the corresponding filepath itself. <STRONG>But at most websites URLs are
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>NOT</STRONG> directly related to physical filename paths, so this assumption
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncwill be usually be wrong!</STRONG> There you have to use the <TT>RewriteBase</TT>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncdirective to specify the correct URL-prefix.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<table width="70%" border=0 bgcolor="#e0e0f0" cellspacing=0 cellpadding=10>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TR><TD>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>Notice:</STRONG> If your webserver's URLs are <STRONG>not</STRONG> directly
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncrelated to physical file paths, you have to use <TT>RewriteBase</TT> in every
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TT>.htaccess</TT> files where you want to use <TT>RewriteRule</TT>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncdirectives.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TD></TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TABLE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>Example:</STRONG>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync Assume the following per-directory config file:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<table border=0 cellspacing=1 cellpadding=5 bgcolor="#f0f0f0">
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TR><TD><PRE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync#
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync# /abc/def/.htaccess -- per-dir config file for directory /abc/def
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync# Remember: /abc/def is the physical path of /xyz, i.e. the server
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync# has a 'Alias /xyz /abc/def' directive e.g.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync#
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncRewriteEngine On
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync# let the server know that we are reached via /xyz and not
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync# via the physical path prefix /abc/def
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncRewriteBase /xyz
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync# now the rewriting rules
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncRewriteRule ^oldstuff\.html$ newstuff.html
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</PRE></TD></TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TABLE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncIn the above example, a request to <TT>/xyz/oldstuff.html</TT> gets correctly
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncrewritten to the physical file <TT>/abc/def/newstuff.html</TT>.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<table width="70%" border=0 bgcolor="#e0e0f0" cellspacing=0 cellpadding=10>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TR><TD>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<font size=-1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>Notice - For the Apache hackers:</STRONG><BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncThe following list gives detailed information about the internal
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncprocessing steps:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<PRE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncRequest:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /xyz/oldstuff.html
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncInternal Processing:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /xyz/oldstuff.html -&gt; /abc/def/oldstuff.html (per-server Alias)
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /abc/def/oldstuff.html -&gt; /abc/def/newstuff.html (per-dir RewriteRule)
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /abc/def/newstuff.html -&gt; /xyz/newstuff.html (per-dir RewriteBase)
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /xyz/newstuff.html -&gt; /abc/def/newstuff.html (per-server Alias)
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncResult:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /abc/def/newstuff.html
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</PRE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncThis seems very complicated but is the correct Apache internal processing,
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncbecause the per-directory rewriting comes too late in the process. So,
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncwhen it occurs the (rewritten) request has to be re-injected into the Apache
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynckernel! BUT: While this seems like a serious overhead, it really isn't, because
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncthis re-injection happens fully internal to the Apache server and the same
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncprocedure is used by many other operations inside Apache. So, you can be
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncsure the design and implementation is correct.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</FONT>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TD></TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TABLE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<hr noshade size=1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<H3><A NAME="RewriteCond">RewriteCond</A></H3>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<A
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync HREF="directive-dict.html#Syntax"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync REL="Help"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync><STRONG>Syntax:</STRONG></A> <CODE>RewriteCond</CODE> <EM>TestString</EM> <EM>CondPattern</EM><BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<A
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync HREF="directive-dict.html#Default"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync REL="Help"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync><STRONG>Default:</STRONG></A> -<EM>None</EM>-<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<A
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync HREF="directive-dict.html#Context"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync REL="Help"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync><STRONG>Context:</STRONG></A> server config, virtual host, per-directory config<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncThe <TT>RewriteCond</TT> directive defines a rule condition. Precede a
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TT>RewriteRule</TT> directive with one or more <TT>RewriteCond</TT>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncdirectives.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncThe following rewriting rule is only used if its pattern matches the current
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncstate of the URI <STRONG>and</STRONG> if these additional conditions apply, too.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<EM>TestString</EM> is a string which can contains the following
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncexpanded constructs in addition to plain text:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<UL>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI><STRONG>RewriteRule backreferences</STRONG>: These are backreferences of the form
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<BLOCKQUOTE><STRONG>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TT>$N</TT>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</STRONG></BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync(1 &lt;= N &lt;= 9) which provide access to the grouped parts (parenthesis!)
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncof the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncpattern from the corresponding <TT>RewriteRule</TT> directive (the one
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncfollowing the current bunch of <TT>RewriteCond</TT> directives).
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI><STRONG>RewriteCond backreferences</STRONG>: These are backreferences of the form
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<BLOCKQUOTE><STRONG>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TT>%N</TT>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</STRONG></BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync(1 &lt;= N &lt;= 9) which provide access to the grouped parts (parenthesis!) of the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncpattern from the last matched <TT>RewriteCond</TT> directive in the current
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncbunch of conditions.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI><STRONG>Server-Variables</STRONG>: These are variables
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync of the form
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<BLOCKQUOTE><STRONG>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TT>%{</TT> <EM>NAME_OF_VARIABLE</EM> <TT>}</TT>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</STRONG></BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncwhere <EM>NAME_OF_VARIABLE</EM> can be a string
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncof the following list:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<table bgcolor="#f0f0f0" cellspacing=0 cellpadding=5>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<td valign=top>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>HTTP headers:</STRONG><P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<font size=-1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncHTTP_USER_AGENT<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncHTTP_REFERER<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncHTTP_COOKIE<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncHTTP_FORWARDED<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncHTTP_HOST<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncHTTP_PROXY_CONNECTION<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncHTTP_ACCEPT<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</FONT>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TD>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<td valign=top>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>connection &amp; request:</STRONG><P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<font size=-1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncREMOTE_ADDR<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncREMOTE_HOST<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncREMOTE_USER<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncREMOTE_IDENT<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncREQUEST_METHOD<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncSCRIPT_FILENAME<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncPATH_INFO<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncQUERY_STRING<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncAUTH_TYPE<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</FONT>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TD>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<td valign=top>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>server internals:</STRONG><P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<font size=-1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncDOCUMENT_ROOT<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncSERVER_ADMIN<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncSERVER_NAME<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncSERVER_PORT<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncSERVER_PROTOCOL<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncSERVER_SOFTWARE<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncSERVER_VERSION<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</FONT>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TD>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<td valign=top>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>system stuff:</STRONG><P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<font size=-1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncTIME_YEAR<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncTIME_MON<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncTIME_DAY<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncTIME_HOUR<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncTIME_MIN<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncTIME_SEC<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncTIME_WDAY<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncTIME<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</FONT>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TD>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<td valign=top>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>specials:</STRONG><P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<font size=-1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncAPI_VERSION<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncTHE_REQUEST<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncREQUEST_URI<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncREQUEST_FILENAME<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncIS_SUBREQ<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</FONT>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TD>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TABLE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<table width="70%" border=0 bgcolor="#e0e0f0" cellspacing=0 cellpadding=10>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TR><TD>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>Notice:</STRONG> These variables all correspond to the similar named
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncHTTP MIME-headers, C variables of the Apache server or <TT>struct tm</TT>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncfields of the Unix system.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TD></TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TABLE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</UL>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncSpecial Notes:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<OL>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>The variables SCRIPT_FILENAME and REQUEST_FILENAME contain the same
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncvalue, i.e. the value of the <TT>filename</TT> field of the internal
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TT>request_rec</TT> structure of the Apache server. The first name is just the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynccommonly known CGI variable name while the second is the consistent
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynccounterpart to REQUEST_URI (which contains the value of the <TT>uri</TT>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncfield of <TT>request_rec</TT>).
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>There is the special format: <TT>%{ENV:variable}</TT> where
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<EM>variable</EM> can be any environment variable. This is looked-up via
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncinternal Apache structures and (if not found there) via <TT>getenv()</TT> from
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncthe Apache server process.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>There is the special format: <TT>%{HTTP:header}</TT> where
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<EM>header</EM> can be any HTTP MIME-header name. This is looked-up
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncfrom the HTTP request. Example: <TT>%{HTTP:Proxy-Connection}</TT>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncis the value of the HTTP header ``<TT>Proxy-Connection:</TT>''.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>There is the special format <TT>%{LA-U:variable}</TT> for look-aheads
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncwhich perform an internal (URL-based) sub-request to determine the final value
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncof <EM>variable</EM>. Use this when you want to use a variable for rewriting
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncwhich actually is set later in an API phase and thus is not available at the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynccurrent stage. For instance when you want to rewrite according to the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TT>REMOTE_USER</TT> variable from within the per-server context
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync(<TT>httpd.conf</TT> file) you have to use <TT>%{LA-U:REMOTE_USER}</TT>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncbecause this variable is set by the authorization phases which come
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<EM>after</EM> the URL translation phase where mod_rewrite operates. On the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncother hand, because mod_rewrite implements its per-directory context
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync(<TT>.htaccess</TT> file) via the Fixup phase of the API and because the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncauthorization phases come <EM>before</EM> this phase, you just can use
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TT>%{REMOTE_USER}</TT> there.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>There is the special format: <TT>%{LA-F:variable}</TT> which perform an
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncinternal (filename-based) sub-request to determine the final value of
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<EM>variable</EM>. This is the most of the time the same as LA-U above.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</OL>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<EM>CondPattern</EM> is the condition pattern, i.e. a regular expression
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncwhich gets applied to the current instance of the <EM>TestString</EM>, i.e.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<EM>TestString</EM> gets evaluated and then matched against
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<EM>CondPattern</EM>.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>Remember:</STRONG> <EM>CondPattern</EM> is a standard
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<EM>Extended Regular Expression</EM> with some additions:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<OL>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>You can precede the pattern string with a '<TT>!</TT>' character
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync(exclamation mark) to specify a <STRONG>non</STRONG>-matching pattern.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncThere are some special variants of <EM>CondPatterns</EM>. Instead of real
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncregular expression strings you can also use one of the following:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<UL>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>'<STRONG>&lt;CondPattern</STRONG>' (is lexicographically lower)<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncTreats the <EM>CondPattern</EM> as a plain string and compares it
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynclexicographically to <EM>TestString</EM> and results in a true expression if
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<EM>TestString</EM> is lexicographically lower then <EM>CondPattern</EM>.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>'<STRONG>&gt;CondPattern</STRONG>' (is lexicographically greater)<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncTreats the <EM>CondPattern</EM> as a plain string and compares it
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynclexicographically to <EM>TestString</EM> and results in a true expression if
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<EM>TestString</EM> is lexicographically greater then <EM>CondPattern</EM>.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>'<STRONG>=CondPattern</STRONG>' (is lexicographically equal)<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncTreats the <EM>CondPattern</EM> as a plain string and compares it
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynclexicographically to <EM>TestString</EM> and results in a true expression if
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<EM>TestString</EM> is lexicographically equal to <EM>CondPattern</EM>, i.e the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynctwo strings are exactly equal (character by character).
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncIf <EM>CondPattern</EM> is just <SAMP>""</SAMP> (two quotation marks) this
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynccompares <EM>TestString</EM> against the empty string.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>'<STRONG>-d</STRONG>' (is <STRONG>d</STRONG>irectory)<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncTreats the <EM>TestString</EM> as a pathname and
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynctests if it exists and is a directory.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>'<STRONG>-f</STRONG>' (is regular <STRONG>f</STRONG>ile)<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncTreats the <EM>TestString</EM> as a pathname and
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynctests if it exists and is a regular file.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>'<STRONG>-s</STRONG>' (is regular file with <STRONG>s</STRONG>ize)<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncTreats the <EM>TestString</EM> as a pathname and
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynctests if it exists and is a regular file with size greater then zero.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>'<STRONG>-l</STRONG>' (is symbolic <STRONG>l</STRONG>ink)<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncTreats the <EM>TestString</EM> as a pathname and
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynctests if it exists and is a symbolic link.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>'<STRONG>-F</STRONG>' (is existing file via subrequest)<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncChecks if <EM>TestString</EM> is a valid file and accessible via all the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncserver's currently-configured access controls for that path. This uses an
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncinternal subrequest to determine the check, so use it with care because it
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncdecreases your servers performance!
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>'<STRONG>-U</STRONG>' (is existing URL via subrequest)<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncChecks if <EM>TestString</EM> is a valid URL and accessible via all the server's
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynccurrently-configured access controls for that path. This uses an internal
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncsubrequest to determine the check, so use it with care because it decreases
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncyour servers performance!
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</UL>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<table width="70%" border=0 bgcolor="#e0e0f0" cellspacing=0 cellpadding=10>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TR><TD>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>Notice:</STRONG>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncAll of these tests can also be prefixed by a not ('!') character
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncto negate their meaning.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TD></TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TABLE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</OL>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncAdditionally you can set special flags for <EM>CondPattern</EM> by appending
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<BLOCKQUOTE><STRONG>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<CODE>[</CODE><EM>flags</EM><CODE>]</CODE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</STRONG></BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncas the third argument to the <TT>RewriteCond</TT> directive. <EM>Flags</EM>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncis a comma-separated list of the following flags:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<UL>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>'<STRONG><CODE>nocase|NC</CODE></STRONG>' (<STRONG>n</STRONG>o <STRONG>c</STRONG>ase)<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync This makes the condition test case-insensitive, i.e. there is
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync no difference between 'A-Z' and 'a-z' both in the expanded
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <EM>TestString</EM> and the <EM>CondPattern</EM>.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>'<STRONG><CODE>ornext|OR</CODE></STRONG>' (<STRONG>or</STRONG> next condition)<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync Use this to combine rule conditions with a local OR instead of the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync implicit AND. Typical example:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<BLOCKQUOTE><PRE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncRewriteCond %{REMOTE_HOST} ^host1.* [OR]
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncRewriteCond %{REMOTE_HOST} ^host2.* [OR]
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncRewriteCond %{REMOTE_HOST} ^host3.*
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncRewriteRule ...some special stuff for any of these hosts...
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</PRE></BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync Without this flag you had to write down the cond/rule three times.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</UL>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>Example:</STRONG>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncTo rewrite the Homepage of a site according to the ``<TT>User-Agent:</TT>''
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncheader of the request, you can use the following:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<BLOCKQUOTE><PRE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncRewriteCond %{HTTP_USER_AGENT} ^Mozilla.*
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncRewriteRule ^/$ /homepage.max.html [L]
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncRewriteCond %{HTTP_USER_AGENT} ^Lynx.*
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncRewriteRule ^/$ /homepage.min.html [L]
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncRewriteRule ^/$ /homepage.std.html [L]
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</PRE></BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncInterpretation: If you use Netscape Navigator as your browser (which identifies
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncitself as 'Mozilla'), then you get the max homepage, which includes
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncFrames, etc. If you use the Lynx browser (which is Terminal-based), then you
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncget the min homepage, which contains no images, no tables, etc. If you
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncuse any other browser you get the standard homepage.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<hr noshade size=1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<H3><A NAME="RewriteRule">RewriteRule</A></H3>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<A
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync HREF="directive-dict.html#Syntax"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync REL="Help"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync><STRONG>Syntax:</STRONG></A> <CODE>RewriteRule</CODE> <EM>Pattern</EM> <EM>Substitution</EM><BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<A
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync HREF="directive-dict.html#Default"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync REL="Help"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync><STRONG>Default:</STRONG></A> -<EM>None</EM>-<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<A
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync HREF="directive-dict.html#Context"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync REL="Help"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync><STRONG>Context:</STRONG></A> server config, virtual host, per-directory config<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncThe <TT>RewriteRule</TT> directive is the real rewriting workhorse. The
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncdirective can occur more than once. Each directive then defines one single
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncrewriting rule. The <STRONG>definition order</STRONG> of these rules is
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>important</STRONG>, because this order is used when applying the rules at
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncrun-time.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<A NAME="patterns"><EM>Pattern</EM></A> can be (for Apache 1.1.x a System
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncV8 and for Apache 1.2.x a POSIX) <A NAME="regexp">regular expression</A>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncwhich gets applied to the current URL. Here ``current'' means the value of the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncURL when this rule gets applied. This may not be the original requested
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncURL, because there could be any number of rules before which already matched
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncand made alterations to it.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncSome hints about the syntax of regular expressions:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<table bgcolor="#f0f0f0" cellspacing=0 cellpadding=5>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<td valign=top>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<PRE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG><CODE>^</CODE></STRONG> Start of line
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG><CODE>$</CODE></STRONG> End of line
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG><CODE>.</CODE></STRONG> Any single character
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG><CODE>[</CODE></STRONG>chars<STRONG><CODE>]</CODE></STRONG> One of chars
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG><CODE>[^</CODE></STRONG>chars<STRONG><CODE>]</CODE></STRONG> None of chars
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG><CODE>?</CODE></STRONG> 0 or 1 of the preceding char
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG><CODE>*</CODE></STRONG> 0 or N of the preceding char
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG><CODE>+</CODE></STRONG> 1 or N of the preceding char
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG><CODE>\</CODE></STRONG>char escape that specific char
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync (e.g. for specifying the chars "<CODE>.[]()</CODE>" etc.)
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG><CODE>(</CODE></STRONG>string<STRONG><CODE>)</CODE></STRONG> Grouping of chars (the <STRONG>N</STRONG>th group can be used on the RHS with <CODE>$</CODE><STRONG>N</STRONG>)
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</PRE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TD>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TABLE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncAdditionally the NOT character ('<TT>!</TT>') is a possible pattern
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncprefix. This gives you the ability to negate a pattern; to say, for instance: ``<EM>if
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncthe current URL does <STRONG>NOT</STRONG> match to this pattern</EM>''. This can be used
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncfor special cases where it is better to match the negative pattern or as a
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynclast default rule.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<table width="70%" border=0 bgcolor="#e0e0f0" cellspacing=0 cellpadding=10>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TR><TD>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>Notice:</STRONG> When using the NOT character to negate a pattern you cannot
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynchave grouped wildcard parts in the pattern. This is impossible because when
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncthe pattern does NOT match, there are no contents for the groups. In
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncconsequence, if negated patterns are used, you cannot use <TT>$N</TT> in the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncsubstitution string!
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TD></TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TABLE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<A NAME="rhs"><EM>Substitution</EM></A> of a rewriting rule is the string
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncwhich is substituted for (or replaces) the original URL for which
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<EM>Pattern</EM> matched. Beside plain text you can use
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<OL>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>back-references <CODE>$N</CODE> to the RewriteRule pattern
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>back-references <CODE>%N</CODE> to the last matched RewriteCond pattern
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>server-variables as in rule condition test-strings (<CODE>%{VARNAME}</CODE>)
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI><A HREF="#mapfunc">mapping-function</A> calls (<CODE>${mapname:key|default}</CODE>)
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</OL>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncBack-references are <CODE>$</CODE><STRONG>N</STRONG> (<STRONG>N</STRONG>=1..9) identifiers which
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncwill be replaced by the contents of the <STRONG>N</STRONG>th group of the matched
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<EM>Pattern</EM>. The server-variables are the same as for the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<EM>TestString</EM> of a <TT>RewriteCond</TT> directive. The
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncmapping-functions come from the <TT>RewriteMap</TT> directive and are
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncexplained there. These three types of variables are expanded in the order of
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncthe above list.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncAs already mentioned above, all the rewriting rules are applied to the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<EM>Substitution</EM> (in the order of definition in the config file). The
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncURL is <STRONG>completely replaced</STRONG> by the <EM>Substitution</EM> and the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncrewriting process goes on until there are no more rules (unless explicitly
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncterminated by a <CODE><STRONG>L</STRONG></CODE> flag - see below).
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncThere is a special substitution string named '<TT>-</TT>' which means:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>NO substitution</STRONG>! Sounds silly? No, it is useful to provide rewriting
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncrules which <STRONG>only</STRONG> match some URLs but do no substitution, e.g. in
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncconjunction with the <STRONG>C</STRONG> (chain) flag to be able to have more than one
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncpattern to be applied before a substitution occurs.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncOne more note: You can even create URLs in the substitution string containing
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynca query string part. Just use a question mark inside the substitution string
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncto indicate that the following stuff should be re-injected into the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncQUERY_STRING. When you want to erase an existing query string, end the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncsubstitution string with just the question mark.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<table width="70%" border=0 bgcolor="#e0e0f0" cellspacing=0 cellpadding=10>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TR><TD>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>Notice</STRONG>: There is a special feature. When you prefix a substitution
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncfield with <TT>http://</TT><EM>thishost</EM>[<EM>:thisport</EM>] then
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>mod_rewrite</STRONG> automatically strips it out. This auto-reduction on
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncimplicit external redirect URLs is a useful and important feature when
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncused in combination with a mapping-function which generates the hostname
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncpart. Have a look at the first example in the example section below to
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncunderstand this.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TD></TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TABLE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<table width="70%" border=0 bgcolor="#e0e0f0" cellspacing=0 cellpadding=10>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TR><TD>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>Remember:</STRONG> An unconditional external redirect to your own server will
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncnot work with the prefix <TT>http://thishost</TT> because of this feature.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncTo achieve such a self-redirect, you have to use the <STRONG>R</STRONG>-flag (see
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncbelow).
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TD></TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TABLE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncAdditionally you can set special flags for <EM>Substitution</EM> by appending
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<BLOCKQUOTE><STRONG>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<CODE>[</CODE><EM>flags</EM><CODE>]</CODE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</STRONG></BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncas the third argument to the <TT>RewriteRule</TT> directive. <EM>Flags</EM> is a
b9a21c3c91c47e090316e28d759194e46628ed49vboxsynccomma-separated list of the following flags:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<UL>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>'<STRONG><CODE>redirect|R</CODE> [=<EM>code</EM>]</STRONG>' (force <A NAME="redirect"><STRONG>r</STRONG>edirect</A>)<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync Prefix <EM>Substitution</EM>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync with <CODE>http://thishost[:thisport]/</CODE> (which makes the new URL a URI) to
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync force a external redirection. If no <EM>code</EM> is given a HTTP response
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync of 302 (MOVED TEMPORARILY) is used. If you want to use other response
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync codes in the range 300-400 just specify them as a number or use
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync one of the following symbolic names: <TT>temp</TT> (default), <TT>permanent</TT>,
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <TT>seeother</TT>.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync Use it for rules which should
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync canonicalize the URL and gives it back to the client, e.g. translate
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync ``<CODE>/~</CODE>'' into ``<CODE>/u/</CODE>'' or always append a slash to
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <CODE>/u/</CODE><EM>user</EM>, etc.<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <STRONG>Notice:</STRONG> When you use this flag, make sure that the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync substitution field is a valid URL! If not, you are redirecting to an
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync invalid location! And remember that this flag itself only prefixes the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync URL with <CODE>http://thishost[:thisport]/</CODE>, but rewriting goes on.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync Usually you also want to stop and do the redirection immediately. To stop
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync the rewriting you also have to provide the 'L' flag.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>'<STRONG><CODE>forbidden|F</CODE></STRONG>' (force URL to be <STRONG>f</STRONG>orbidden)<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync This forces the current URL to be forbidden, i.e. it immediately sends
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync back a HTTP response of 403 (FORBIDDEN). Use this flag in conjunction with
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync appropriate RewriteConds to conditionally block some URLs.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>'<STRONG><CODE>gone|G</CODE></STRONG>' (force URL to be <STRONG>g</STRONG>one)<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync This forces the current URL to be gone, i.e. it immediately sends back a
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync HTTP response of 410 (GONE). Use this flag to mark no longer existing
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync pages as gone.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>'<STRONG><CODE>proxy|P</CODE></STRONG>' (force <STRONG>p</STRONG>roxy)<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync This flag forces the substitution part to be internally forced as a proxy
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync request and immediately (i.e. rewriting rule processing stops here) put
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync through the proxy module. You have to make sure that the substitution
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync string is a valid URI (e.g. typically <TT>http://</TT>) which can
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync be handled by the Apache proxy module. If not you get an error from
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync the proxy module. Use this flag to achieve a more powerful implementation
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync of the <TT>mod_proxy</TT> directive <TT>ProxyPass</TT>, to map
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync some remote stuff into the namespace of the local server.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync Notice: <STRONG>You really have to put <TT>ProxyRequests On</TT> into your
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync server configuration to prevent proxy requests from leading to core-dumps
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync inside the Apache kernel. If you have not compiled in the proxy module,
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync then there is no core-dump problem, because mod_rewrite checks for
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync existence of the proxy module and if lost forbids proxy URLs. </STRONG>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>'<STRONG><CODE>last|L</CODE></STRONG>' (<STRONG>l</STRONG>ast rule)<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync Stop the rewriting process here and
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync don't apply any more rewriting rules. This corresponds to the Perl
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <CODE>last</CODE> command or the <CODE>break</CODE> command from the C
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync language. Use this flag to prevent the currently rewritten URL from being
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync rewritten further by following rules which may be wrong. For
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync example, use it to rewrite the root-path URL ('<CODE>/</CODE>') to a real
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync one, e.g. '<CODE>/e/www/</CODE>'.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>'<STRONG><CODE>next|N</CODE></STRONG>' (<STRONG>n</STRONG>ext round)<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync Re-run the rewriting process (starting again with the first rewriting
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync rule). Here the URL to match is again not the original URL but the URL
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync from the last rewriting rule. This corresponds to the Perl
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <CODE>next</CODE> command or the <CODE>continue</CODE> command from the C
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync language. Use this flag to restart the rewriting process, i.e. to
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync immediately go to the top of the loop. <BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <STRONG>But be careful not to create a deadloop!</STRONG>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>'<STRONG><CODE>chain|C</CODE></STRONG>' (<STRONG>c</STRONG>hained with next rule)<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync This flag chains the current rule with the next rule (which itself can
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync also be chained with its following rule, etc.). This has the following
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync effect: if a rule matches, then processing continues as usual, i.e. the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync flag has no effect. If the rule does <STRONG>not</STRONG> match, then all following
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync chained rules are skipped. For instance, use it to remove the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync ``<TT>.www</TT>'' part inside a per-directory rule set when you let an
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync external redirect happen (where the ``<TT>.www</TT>'' part should not to
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync occur!).
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>'<STRONG><CODE>type|T</CODE></STRONG>=<EM>mime-type</EM>' (force MIME <STRONG>t</STRONG>ype)<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync Force the MIME-type of the target file to be <EM>mime-type</EM>. For
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync instance, this can be used to simulate the old <TT>mod_alias</TT>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync directive <TT>ScriptAlias</TT> which internally forces all files inside
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync the mapped directory to have a MIME type of
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync ``<TT>application/x-httpd-cgi</TT>''.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>'<STRONG><CODE>nosubreq|NS</CODE></STRONG>' (used only if <STRONG>n</STRONG>o internal <STRONG>s</STRONG>ub-request)<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync This flag forces the rewriting engine to skip a rewriting rule if the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync current request is an internal sub-request. For instance, sub-requests
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync occur internally in Apache when <TT>mod_include</TT> tries to find out
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync information about possible directory default files (<TT>index.xxx</TT>).
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync On sub-requests it is not always useful and even sometimes causes a failure to
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync if the complete set of rules are applied. Use this flag to exclude some rules.<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync Use the following rule for your decision: whenever you prefix some URLs
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync with CGI-scripts to force them to be processed by the CGI-script, the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync chance is high that you will run into problems (or even overhead) on sub-requests.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync In these cases, use this flag.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>'<STRONG><CODE>qsappend|QSA</CODE></STRONG>' (<STRONG>q</STRONG>uery <STRONG>s</STRONG>tring
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <STRONG>a</STRONG>ppend)<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync This flag forces the rewriting engine to append a query
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync string part in the substitution string to the existing one instead of
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync replacing it. Use this when you want to add more data to the query string
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync via a rewrite rule.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>'<STRONG><CODE>passthrough|PT</CODE></STRONG>' (<STRONG>p</STRONG>ass <STRONG>t</STRONG>hrough to next handler)<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync This flag forces the rewriting engine to set the <CODE>uri</CODE> field
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync of the internal <CODE>request_rec</CODE> structure to the value
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync of the <CODE>filename</CODE> field. This flag is just a hack to be able
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync to post-process the output of <TT>RewriteRule</TT> directives by
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <TT>Alias</TT>, <TT>ScriptAlias</TT>, <TT>Redirect</TT>, etc. directives
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync from other URI-to-filename translators. A trivial example to show the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync semantics:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync If you want to rewrite <TT>/abc</TT> to <TT>/def</TT> via the rewriting
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync engine of <TT>mod_rewrite</TT> and then <TT>/def</TT> to <TT>/ghi</TT>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync with <TT>mod_alias</TT>:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <PRE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync RewriteRule ^/abc(.*) /def$1 [PT]
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync Alias /def /ghi
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </PRE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync If you omit the <TT>PT</TT> flag then <TT>mod_rewrite</TT>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync will do its job fine, i.e. it rewrites <TT>uri=/abc/...</TT> to
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <TT>filename=/def/...</TT> as a full API-compliant URI-to-filename
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync translator should do. Then <TT>mod_alias</TT> comes and tries to do a
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync URI-to-filename transition which will not work.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync Notice: <STRONG>You have to use this flag if you want to intermix directives
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync of different modules which contain URL-to-filename translators</STRONG>. The
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync typical example is the use of <TT>mod_alias</TT> and
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <TT>mod_rewrite</TT>..
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<table width="70%" border=0 bgcolor="#e0e0f0" cellspacing=0 cellpadding=10>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TR><TD>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<font size=-1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <STRONG>Notice - For the Apache hackers:</STRONG><BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync If the current Apache API had a
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync filename-to-filename hook additionally to the URI-to-filename hook then
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync we wouldn't need this flag! But without such a hook this flag is the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync only solution. The Apache Group has discussed this problem and will
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync add such hooks into Apache version 2.0.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</FONT>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TD></TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TABLE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>'<STRONG><CODE>skip|S</CODE></STRONG>=<EM>num</EM>' (<STRONG>s</STRONG>kip next rule(s))<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync This flag forces the rewriting engine to skip the next <EM>num</EM> rules
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync in sequence when the current rule matches. Use this to make pseudo
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync if-then-else constructs: The last rule of the then-clause becomes
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync a <TT>skip=N</TT> where N is the number of rules in the else-clause.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync (This is <STRONG>not</STRONG> the same as the 'chain|C' flag!)
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<LI>'<STRONG><CODE>env|E=</CODE></STRONG><EM>VAR</EM>:<EM>VAL</EM>' (set <STRONG>e</STRONG>nvironment variable)<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync This forces an environment variable named <EM>VAR</EM> to be set to the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync value <EM>VAL</EM>, where <EM>VAL</EM> can contain regexp backreferences
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <TT>$N</TT> and <TT>%N</TT> which will be expanded. You can use this flag
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync more than once to set more than one variable. The variables can be later
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync dereferenced at a lot of situations, but the usual location will be from
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync within XSSI (via <TT>&lt;!--#echo var="VAR"--&gt;</TT>) or CGI (e.g.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <TT>$ENV{'VAR'}</TT>). But additionally you can also dereference it in a
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync following RewriteCond pattern via <TT>%{ENV:VAR}</TT>. Use this to strip
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync but remember information from URLs.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</UL>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<table width="70%" border=0 bgcolor="#e0e0f0" cellspacing=0 cellpadding=10>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TR><TD>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>Notice:</STRONG> Never forget that <EM>Pattern</EM> gets applied to a complete URL
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncin per-server configuration files. <STRONG>But in per-directory configuration
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncfiles, the per-directory prefix (which always is the same for a specific
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncdirectory!) gets automatically <EM>removed</EM> for the pattern matching and
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncautomatically <EM>added</EM> after the substitution has been done.</STRONG> This feature is
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncessential for many sorts of rewriting, because without this prefix stripping
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncyou have to match the parent directory which is not always possible.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncThere is one exception: If a substitution string starts with
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync``<TT>http://</TT>'' then the directory prefix will be <STRONG>not</STRONG> added and a
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncexternal redirect or proxy throughput (if flag <STRONG>P</STRONG> is used!) is forced!
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TD></TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TABLE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<table width="70%" border=0 bgcolor="#e0e0f0" cellspacing=0 cellpadding=10>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TR><TD>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>Notice:</STRONG> To enable the rewriting engine for per-directory configuration files
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncyou need to set ``<TT>RewriteEngine On</TT>'' in these files <STRONG>and</STRONG>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync``<TT>Option FollowSymLinks</TT>'' enabled. If your administrator has
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncdisabled override of <TT>FollowSymLinks</TT> for a user's directory, then
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncyou cannot use the rewriting engine. This restriction is needed for
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncsecurity reasons.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TD></TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TABLE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncHere are all possible substitution combinations and their meanings:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>Inside per-server configuration (<TT>httpd.conf</TT>)<BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncfor request ``<TT>GET /somepath/pathinfo</TT>'':</STRONG><BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<table bgcolor="#f0f0f0" cellspacing=0 cellpadding=5>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TD>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<PRE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>Given Rule</STRONG> <STRONG>Resulting Substitution</STRONG>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync---------------------------------------------- ----------------------------------
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync^/somepath(.*) otherpath$1 not supported, because invalid!
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync^/somepath(.*) otherpath$1 [R] not supported, because invalid!
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync^/somepath(.*) otherpath$1 [P] not supported, because invalid!
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync---------------------------------------------- ----------------------------------
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync^/somepath(.*) /otherpath$1 /otherpath/pathinfo
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync^/somepath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync via external redirection
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync^/somepath(.*) /otherpath$1 [P] not supported, because silly!
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync---------------------------------------------- ----------------------------------
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync^/somepath(.*) http://thishost/otherpath$1 /otherpath/pathinfo
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync^/somepath(.*) http://thishost/otherpath$1 [R] http://thishost/otherpath/pathinfo
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync via external redirection
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync^/somepath(.*) http://thishost/otherpath$1 [P] not supported, because silly!
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync---------------------------------------------- ----------------------------------
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync^/somepath(.*) http://otherhost/otherpath$1 http://otherhost/otherpath/pathinfo
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync via external redirection
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync^/somepath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfo
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync via external redirection
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync (the [R] flag is redundant)
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync^/somepath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfo
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync via internal proxy
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</PRE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TD>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TABLE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>Inside per-directory configuration for <TT>/somepath</TT><BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync(i.e. file <TT>.htaccess</TT> in dir <TT>/physical/path/to/somepath</TT> containing
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TT>RewriteBase /somepath</TT>)<BR> for
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncrequest ``<TT>GET /somepath/localpath/pathinfo</TT>'':</STRONG><BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<table bgcolor="#f0f0f0" cellspacing=0 cellpadding=5>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<TD>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<PRE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>Given Rule</STRONG> <STRONG>Resulting Substitution</STRONG>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync---------------------------------------------- ----------------------------------
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync^localpath(.*) otherpath$1 /somepath/otherpath/pathinfo
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync^localpath(.*) otherpath$1 [R] http://thishost/somepath/otherpath/pathinfo
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync via external redirection
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync^localpath(.*) otherpath$1 [P] not supported, because silly!
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync---------------------------------------------- ----------------------------------
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync^localpath(.*) /otherpath$1 /otherpath/pathinfo
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync^localpath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync via external redirection
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync^localpath(.*) /otherpath$1 [P] not supported, because silly!
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync---------------------------------------------- ----------------------------------
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync^localpath(.*) http://thishost/otherpath$1 /otherpath/pathinfo
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync^localpath(.*) http://thishost/otherpath$1 [R] http://thishost/otherpath/pathinfo
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync via external redirection
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync^localpath(.*) http://thishost/otherpath$1 [P] not supported, because silly!
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync---------------------------------------------- ----------------------------------
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync^localpath(.*) http://otherhost/otherpath$1 http://otherhost/otherpath/pathinfo
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync via external redirection
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync^localpath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfo
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync via external redirection
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync (the [R] flag is redundant)
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync^localpath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfo
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync via internal proxy
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</PRE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TD>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</TABLE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>Example:</STRONG>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncWe want to rewrite URLs of the form
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<CODE>/</CODE> <EM>Language</EM>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<CODE>/~</CODE> <EM>Realname</EM>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<CODE>/.../</CODE> <EM>File</EM>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncinto
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<CODE>/u/</CODE> <EM>Username</EM>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<CODE>/.../</CODE> <EM>File</EM>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<CODE>.</CODE> <EM>Language</EM>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncWe take the rewrite mapfile from above and save it under
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<CODE>/anywhere/map.real-to-user</CODE>. Then we only have to add the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncfollowing lines to the Apache server configuration file:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<PRE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncRewriteLog /anywhere/rewrite.log
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncRewriteMap real-to-user txt:/anywhere/map.real-to-host
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncRewriteRule ^/([^/]+)/~([^/]+)/(.*)$ /u/${real-to-user:$2|nobody}/$3.$1
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</PRE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<HR NOSHADE SIZE=1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<CENTER>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<H1><A NAME="Miscelleneous">Miscellaneous</A></H1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</CENTER>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<HR NOSHADE SIZE=1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<H2><A NAME="EnvVar">Environment Variables</A></H2>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncThis module keeps track of two additional (non-standard) CGI/SSI environment
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncvariables named <TT>SCRIPT_URL</TT> and <TT>SCRIPT_URI</TT>. These contain
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncthe <EM>logical</EM> Web-view to the current resource, while the standard CGI/SSI
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncvariables <TT>SCRIPT_NAME</TT> and <TT>SCRIPT_FILENAME</TT> contain the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<EM>physical</EM> System-view.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncNotice: These variables hold the URI/URL <EM>as they were initially
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncrequested</EM>, i.e. in a state <EM>before</EM> any rewriting. This is
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncimportant because the rewriting process is primarily used to rewrite logical
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncURLs to physical pathnames.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<P>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>Example:</STRONG>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<PRE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncSCRIPT_NAME=/v/sw/free/lib/apache/global/u/rse/.www/index.html
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncSCRIPT_FILENAME=/u/rse/.www/index.html
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncSCRIPT_URL=/u/rse/
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncSCRIPT_URI=http://en2.en.sdm.de/u/rse/
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</PRE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<HR NOSHADE SIZE=1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<H2><A NAME="Solutions">Practical Solutions</A></H2>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncThere is a comprehensive collection of practical solutions for URL-based
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncproblems available by the author of mod_rewrite. Here you will find real-life
b9a21c3c91c47e090316e28d759194e46628ed49vboxsyncrulesets and additional information.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG>Apache URL Rewriting Guide</STRONG><BR>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<STRONG><A HREF="http://www.engelschall.com/pw/apache/rewriteguide/"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync >http://www.engelschall.com/pw/apache/rewriteguide/</A></STRONG>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<!--#include virtual="footer.html" -->
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<BLOCKQUOTE>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</BODY>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</HTML>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<!--/%hypertext -->
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync