home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 May / Gamestar_62_2004-05_dvd.iso / Programy / apache_2.0.48-win32-x86-no_ssl.msi / Data.Cab / F252772_mod_rewrite.xml < prev    next >
Extensible Markup Language  |  2003-10-10  |  75KB  |  1,760 lines

  1. <?xml version="1.0"?>
  2. <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
  3. <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
  4. <modulesynopsis metafile="mod_rewrite.xml.meta">
  5.  
  6. <name>mod_rewrite</name> 
  7.  
  8. <description>Provides a rule-based rewriting engine to rewrite requested
  9. URLs on the fly</description>
  10.  
  11. <status>Extension</status>
  12. <sourcefile>mod_rewrite.c</sourcefile>
  13. <identifier>rewrite_module</identifier>
  14. <compatibility>Available in Apache 1.3 and later</compatibility>
  15.  
  16. <summary>
  17.       <blockquote>
  18.             <p>``The great thing about mod_rewrite is it gives you
  19.             all the configurability and flexibility of Sendmail.
  20.             The downside to mod_rewrite is that it gives you all
  21.             the configurability and flexibility of Sendmail.''</p>
  22.  
  23.             <p class="cite">-- <cite>Brian Behlendorf</cite><br />
  24.             Apache Group</p>
  25.  
  26.       </blockquote>
  27.  
  28.       <blockquote>
  29.             <p>`` Despite the tons of examples and docs,
  30.             mod_rewrite is voodoo. Damned cool voodoo, but still
  31.             voodoo. ''</p>
  32.  
  33.             <p class="cite">-- <cite>Brian Moore</cite><br />
  34.             bem@news.cmc.net</p>
  35.  
  36.       </blockquote>
  37.  
  38.  
  39.       <p>Welcome to mod_rewrite, the Swiss Army Knife of URL
  40.       manipulation!</p>
  41.  
  42.       <p>This module uses a rule-based rewriting engine (based on a
  43.       regular-expression parser) to rewrite requested URLs on the
  44.       fly. It supports an unlimited number of rules and an
  45.       unlimited number of attached rule conditions for each rule to
  46.       provide a really flexible and powerful URL manipulation
  47.       mechanism. The URL manipulations can depend on various tests,
  48.       for instance server variables, environment variables, HTTP
  49.       headers, time stamps and even external database lookups in
  50.       various formats can be used to achieve a really granular URL
  51.       matching.</p>
  52.  
  53.       <p>This module operates on the full URLs (including the
  54.       path-info part) both in per-server context
  55.       (<code>httpd.conf</code>) and per-directory context
  56.       (<code>.htaccess</code>) and can even generate query-string
  57.       parts on result. The rewritten result can lead to internal
  58.       sub-processing, external request redirection or even to an
  59.       internal proxy throughput.</p>
  60.  
  61.       <p>But all this functionality and flexibility has its
  62.       drawback: complexity. So don't expect to understand this
  63.       entire module in just one day.</p>
  64.  
  65.       <p>This module was invented and originally written in April
  66.       1996 and gifted exclusively to the The Apache Group in July 1997
  67.       by</p>
  68.  
  69.       <p class="indent">
  70.         <a href="http://www.engelschall.com/"><code>Ralf S.
  71.         Engelschall</code></a><br />
  72.          <a
  73.         href="mailto:rse@engelschall.com"><code>rse@engelschall.com</code></a><br />
  74.          <a
  75.         href="http://www.engelschall.com/"><code>www.engelschall.com</code></a>
  76.       </p>
  77. </summary>
  78.  
  79. <section id="Internal"><title>Internal Processing</title>
  80.  
  81.       <p>The internal processing of this module is very complex but
  82.       needs to be explained once even to the average user to avoid
  83.       common mistakes and to let you exploit its full
  84.       functionality.</p>
  85.  
  86. <section id="InternalAPI"><title>API Phases</title>
  87.  
  88.       <p>First you have to understand that when Apache processes a
  89.       HTTP request it does this in phases. A hook for each of these
  90.       phases is provided by the Apache API. Mod_rewrite uses two of
  91.       these hooks: the URL-to-filename translation hook which is
  92.       used after the HTTP request has been read but before any
  93.       authorization starts and the Fixup hook which is triggered
  94.       after the authorization phases and after the per-directory
  95.       config files (<code>.htaccess</code>) have been read, but
  96.       before the content handler is activated.</p>
  97.  
  98.       <p>So, after a request comes in and Apache has determined the
  99.       corresponding server (or virtual server) the rewriting engine
  100.       starts processing of all mod_rewrite directives from the
  101.       per-server configuration in the URL-to-filename phase. A few
  102.       steps later when the final data directories are found, the
  103.       per-directory configuration directives of mod_rewrite are
  104.       triggered in the Fixup phase. In both situations mod_rewrite
  105.       rewrites URLs either to new URLs or to filenames, although
  106.       there is no obvious distinction between them. This is a usage
  107.       of the API which was not intended to be this way when the API
  108.       was designed, but as of Apache 1.x this is the only way
  109.       mod_rewrite can operate. To make this point more clear
  110.       remember the following two points:</p>
  111.  
  112.       <ol>
  113.         <li>Although mod_rewrite rewrites URLs to URLs, URLs to
  114.         filenames and even filenames to filenames, the API
  115.         currently provides only a URL-to-filename hook. In Apache
  116.         2.0 the two missing hooks will be added to make the
  117.         processing more clear. But this point has no drawbacks for
  118.         the user, it is just a fact which should be remembered:
  119.         Apache does more in the URL-to-filename hook than the API
  120.         intends for it.</li>
  121.  
  122.         <li>
  123.           Unbelievably mod_rewrite provides URL manipulations in
  124.           per-directory context, <em>i.e.</em>, within
  125.           <code>.htaccess</code> files, although these are reached
  126.           a very long time after the URLs have been translated to
  127.           filenames. It has to be this way because
  128.           <code>.htaccess</code> files live in the filesystem, so
  129.           processing has already reached this stage. In other
  130.           words: According to the API phases at this time it is too
  131.           late for any URL manipulations. To overcome this chicken
  132.           and egg problem mod_rewrite uses a trick: When you
  133.           manipulate a URL/filename in per-directory context
  134.           mod_rewrite first rewrites the filename back to its
  135.           corresponding URL (which is usually impossible, but see
  136.           the <code>RewriteBase</code> directive below for the
  137.           trick to achieve this) and then initiates a new internal
  138.           sub-request with the new URL. This restarts processing of
  139.           the API phases. 
  140.  
  141.           <p>Again mod_rewrite tries hard to make this complicated
  142.           step totally transparent to the user, but you should
  143.           remember here: While URL manipulations in per-server
  144.           context are really fast and efficient, per-directory
  145.           rewrites are slow and inefficient due to this chicken and
  146.           egg problem. But on the other hand this is the only way
  147.           mod_rewrite can provide (locally restricted) URL
  148.           manipulations to the average user.</p>
  149.         </li>
  150.       </ol>
  151.  
  152.       <p>Don't forget these two points!</p>
  153. </section>
  154.  
  155. <section id="InternalRuleset"><title>Ruleset Processing</title>
  156.  
  157.       <p>Now when mod_rewrite is triggered in these two API phases, it
  158.       reads the configured rulesets from its configuration
  159.       structure (which itself was either created on startup for
  160.       per-server context or during the directory walk of the Apache
  161.       kernel for per-directory context). Then the URL rewriting
  162.       engine is started with the contained ruleset (one or more
  163.       rules together with their conditions). The operation of the
  164.       URL rewriting engine itself is exactly the same for both
  165.       configuration contexts. Only the final result processing is
  166.       different. </p>
  167.  
  168.       <p>The order of rules in the ruleset is important because the
  169.       rewriting engine processes them in a special (and not very
  170.       obvious) order. The rule is this: The rewriting engine loops
  171.       through the ruleset rule by rule (<directive
  172.       module="mod_rewrite">RewriteRule</directive> directives) and
  173.       when a particular rule matches it optionally loops through
  174.       existing corresponding conditions (<code>RewriteCond</code>
  175.       directives). For historical reasons the conditions are given
  176.       first, and so the control flow is a little bit long-winded. See
  177.       Figure 1 for more details.</p>
  178. <p class="figure">
  179.       <img src="../images/mod_rewrite_fig1.gif" width="428"
  180.            height="385" alt="[Needs graphics capability to display]" /><br />
  181.       <dfn>Figure 1:</dfn>The control flow through the rewriting ruleset
  182. </p>
  183.       <p>As you can see, first the URL is matched against the
  184.       <em>Pattern</em> of each rule. When it fails mod_rewrite
  185.       immediately stops processing this rule and continues with the
  186.       next rule. If the <em>Pattern</em> matches, mod_rewrite looks
  187.       for corresponding rule conditions. If none are present, it
  188.       just substitutes the URL with a new value which is
  189.       constructed from the string <em>Substitution</em> and goes on
  190.       with its rule-looping. But if conditions exist, it starts an
  191.       inner loop for processing them in the order that they are
  192.       listed. For conditions the logic is different: we don't match
  193.       a pattern against the current URL. Instead we first create a
  194.       string <em>TestString</em> by expanding variables,
  195.       back-references, map lookups, <em>etc.</em> and then we try
  196.       to match <em>CondPattern</em> against it. If the pattern
  197.       doesn't match, the complete set of conditions and the
  198.       corresponding rule fails. If the pattern matches, then the
  199.       next condition is processed until no more conditions are
  200.       available. If all conditions match, processing is continued
  201.       with the substitution of the URL with
  202.       <em>Substitution</em>.</p>
  203.  
  204. </section>
  205.  
  206. <section id="quoting"><title>Quoting Special Characters</title>
  207.  
  208.       <p>As of Apache 1.3.20, special characters in
  209.       <em>TestString</em> and <em>Substitution</em> strings can be
  210.       escaped (that is, treated as normal characters without their
  211.       usual special meaning) by prefixing them with a slosh ('\')
  212.       character. In other words, you can include an actual
  213.       dollar-sign character in a <em>Substitution</em> string by
  214.       using '<code>\$</code>'; this keeps mod_rewrite from trying
  215.       to treat it as a backreference.</p>
  216. </section>
  217.  
  218. <section id="InternalBackRefs"><title>Regex Back-Reference Availability</title>
  219.  
  220.       <p>One important thing here has to be remembered: Whenever you
  221.       use parentheses in <em>Pattern</em> or in one of the
  222.       <em>CondPattern</em>, back-references are internally created
  223.       which can be used with the strings <code>$N</code> and
  224.       <code>%N</code> (see below). These are available for creating
  225.       the strings <em>Substitution</em> and <em>TestString</em>.
  226.       Figure 2 shows to which locations the back-references are
  227.       transfered for expansion.</p>
  228.  
  229. <p class="figure">
  230.       <img src="../images/mod_rewrite_fig2.gif" width="381"
  231.            height="179" alt="[Needs graphics capability to display]" /><br />
  232.       <dfn>Figure 2:</dfn> The back-reference flow through a rule.
  233. </p>
  234.       <p>We know this was a crash course on mod_rewrite's internal
  235.       processing. But you will benefit from this knowledge when
  236.       reading the following documentation of the available
  237.       directives.</p>
  238.  
  239. </section>
  240. </section>
  241.  
  242. <section id="EnvVar"><title>Environment Variables</title>
  243.  
  244.       <p>This module keeps track of two additional (non-standard)
  245.       CGI/SSI environment variables named <code>SCRIPT_URL</code>
  246.       and <code>SCRIPT_URI</code>. These contain the
  247.       <em>logical</em> Web-view to the current resource, while the
  248.       standard CGI/SSI variables <code>SCRIPT_NAME</code> and
  249.       <code>SCRIPT_FILENAME</code> contain the <em>physical</em>
  250.       System-view. </p>
  251.  
  252.       <p>Notice: These variables hold the URI/URL <em>as they were
  253.       initially requested</em>, <em>i.e.</em>, <em>before</em> any
  254.       rewriting. This is important because the rewriting process is
  255.       primarily used to rewrite logical URLs to physical
  256.       pathnames.</p>
  257.  
  258. <example><title>Example</title>
  259. <pre>
  260. SCRIPT_NAME=/sw/lib/w3s/tree/global/u/rse/.www/index.html
  261. SCRIPT_FILENAME=/u/rse/.www/index.html
  262. SCRIPT_URL=/u/rse/
  263. SCRIPT_URI=http://en1.engelschall.com/u/rse/
  264. </pre>
  265. </example>
  266.  
  267. </section>
  268.  
  269. <section id="Solutions"><title>Practical Solutions</title>
  270.  
  271.       <p>We also have an <a href="../misc/rewriteguide.html">URL
  272.       Rewriting Guide</a> available, which provides a collection of
  273.       practical solutions for URL-based problems. There you can
  274.       find real-life rulesets and additional information about
  275.       mod_rewrite.</p>
  276. </section>
  277.  
  278.  
  279. <directivesynopsis>
  280. <name>RewriteEngine</name>
  281. <description>Enables or disables runtime rewriting engine</description>
  282. <syntax>RewriteEngine on|off</syntax>
  283. <default>RewriteEngine off</default>
  284. <contextlist><context>server config</context><context>virtual host</context>
  285. <context>directory</context><context>.htaccess</context></contextlist>
  286. <override>FileInfo</override>
  287.  
  288. <usage>       
  289.  
  290.       <p>The <directive>RewriteEngine</directive> directive enables or
  291.       disables the runtime rewriting engine. If it is set to
  292.       <code>off</code> this module does no runtime processing at
  293.       all. It does not even update the <code>SCRIPT_URx</code>
  294.       environment variables.</p>
  295.  
  296.       <p>Use this directive to disable the module instead of
  297.       commenting out all the <directive
  298.       module="mod_rewrite">RewriteRule</directive> directives!</p>
  299.  
  300.       <p>Note that, by default, rewrite configurations are not
  301.       inherited. This means that you need to have a
  302.       <code>RewriteEngine on</code> directive for each virtual host
  303.       in which you wish to use it.</p>
  304. </usage>
  305.  
  306. </directivesynopsis>
  307.  
  308. <directivesynopsis>
  309. <name>RewriteOptions</name>
  310. <description>Sets some special options for the rewrite engine</description>
  311. <syntax>RewriteOptions <var>Options</var></syntax>
  312. <default>RewriteOptions MaxRedirects=10</default>
  313. <contextlist><context>server config</context><context>virtual host</context>
  314. <context>directory</context><context>.htaccess</context></contextlist>
  315. <override>FileInfo</override>
  316. <compatibility><code>MaxRedirects</code> is available in Apache 2.0.45 and
  317. later</compatibility>
  318. <usage>
  319.  
  320.       <p>The <directive>RewriteOptions</directive> directive sets some
  321.       special options for the current per-server or per-directory
  322.       configuration. The <em>Option</em> strings can be one of the
  323.       following:</p>
  324.  
  325.       <dl>
  326.       <dt><code>inherit</code></dt>
  327.       <dd>This forces the current configuration to inherit the
  328.       configuration of the parent. In per-virtual-server context
  329.       this means that the maps, conditions and rules of the main
  330.       server are inherited. In per-directory context this means
  331.       that conditions and rules of the parent directory's
  332.       <code>.htaccess</code> configuration are inherited.</dd>
  333.  
  334.       <dt><code>MaxRedirects=<var>number</var></code></dt>
  335.       <dd>In order to prevent endless loops of internal redirects
  336.       issued by per-directory <directive module="mod_rewrite"
  337.       >RewriteRule</directive>s, <module>mod_rewrite</module> aborts
  338.       the request after reaching a maximum number of such redirects and
  339.       responds with an 500 Internal Server Error. If you really need
  340.       more internal redirects than 10 per request, you may increase
  341.       the default to the desired value.</dd>
  342.       </dl>
  343. </usage>
  344.  
  345. </directivesynopsis>
  346.  
  347. <directivesynopsis>
  348. <name>RewriteLog</name>
  349. <description>Sets the name of the file used for logging rewrite engine
  350. processing</description>
  351. <syntax>RewriteLog <em>file-path</em></syntax>
  352. <contextlist><context>server config</context><context>virtual host</context>
  353. </contextlist>
  354.  
  355. <usage>
  356.       <p>The <directive>RewriteLog</directive> directive sets the name
  357.       of the file to which the server logs any rewriting actions it
  358.       performs. If the name does not begin with a slash
  359.       ('<code>/</code>') then it is assumed to be relative to the
  360.       <em>Server Root</em>. The directive should occur only once per
  361.       server config.</p>
  362.  
  363. <note>    To disable the logging of
  364.           rewriting actions it is not recommended to set
  365.           <em>Filename</em> to <code>/dev/null</code>, because
  366.           although the rewriting engine does not then output to a
  367.           logfile it still creates the logfile output internally.
  368.           <strong>This will slow down the server with no advantage
  369.           to the administrator!</strong> To disable logging either
  370.           remove or comment out the <directive>RewriteLog</directive>
  371.           directive or use <code>RewriteLogLevel 0</code>!
  372. </note>
  373.  
  374. <note type="securitywarning"><title>Security</title>
  375.  
  376. See the <a href="../misc/security_tips.html">Apache Security Tips</a>
  377. document for details on why your security could be compromised if the
  378. directory where logfiles are stored is writable by anyone other than
  379. the user that starts the server.
  380. </note>
  381.  
  382. <example><title>Example</title>
  383. RewriteLog "/usr/local/var/apache/logs/rewrite.log"
  384. </example>
  385.  
  386. </usage>
  387.  
  388. </directivesynopsis>
  389.  
  390. <directivesynopsis>
  391. <name>RewriteLogLevel</name>
  392. <description>Sets the verbosity of the log file used by the rewrite
  393. engine</description>
  394. <syntax>RewriteLogLevel <em>Level</em></syntax>
  395. <default>RewriteLogLevel 0</default>
  396. <contextlist><context>server config</context><context>virtual host</context>
  397. </contextlist>
  398.  
  399. <usage>
  400.       <p>The <directive>RewriteLogLevel</directive> directive sets the
  401.       verbosity level of the rewriting logfile. The default level 0
  402.       means no logging, while 9 or more means that practically all
  403.       actions are logged.</p>
  404.  
  405.       <p>To disable the logging of rewriting actions simply set
  406.       <em>Level</em> to 0. This disables all rewrite action
  407.       logs.</p>
  408.  
  409. <note> Using a high value for
  410.           <em>Level</em> will slow down your Apache server
  411.           dramatically! Use the rewriting logfile at a
  412.           <em>Level</em> greater than 2 only for debugging!
  413. </note>
  414.  
  415. <example><title>Example</title>
  416. RewriteLogLevel 3
  417. </example>
  418.  
  419. </usage>
  420.  
  421. </directivesynopsis>
  422.  
  423. <directivesynopsis>
  424. <name>RewriteLock</name>
  425. <description>Sets the name of the lock file used for <directive
  426. module="mod_rewrite">RewriteMap</directive>
  427. synchronization</description>
  428. <syntax>RewriteLock <em>file-path</em></syntax>
  429. <contextlist><context>server config</context></contextlist>
  430.  
  431. <usage>
  432.       <p>This directive sets the filename for a synchronization
  433.       lockfile which mod_rewrite needs to communicate with <directive
  434.       module="mod_rewrite">RewriteMap</directive>
  435.       <em>programs</em>. Set this lockfile to a local path (not on a
  436.       NFS-mounted device) when you want to use a rewriting
  437.       map-program. It is not required for other types of rewriting
  438.       maps.</p>
  439. </usage>
  440.  
  441. </directivesynopsis>
  442.  
  443. <directivesynopsis>
  444. <name>RewriteMap</name>
  445. <description>Defines a mapping function for key-lookup</description>
  446. <syntax>RewriteMap <em>MapName</em> <em>MapType</em>:<em>MapSource</em>
  447. </syntax>
  448. <contextlist><context>server config</context><context>virtual host</context>
  449. </contextlist>
  450. <compatibility>The choice of different dbm types is available in
  451. Apache 2.0.41 and later</compatibility>
  452.  
  453. <usage>
  454.       <p>The <directive>RewriteMap</directive> directive defines a
  455.       <em>Rewriting Map</em> which can be used inside rule
  456.       substitution strings by the mapping-functions to
  457.       insert/substitute fields through a key lookup. The source of
  458.       this lookup can be of various types.</p>
  459.  
  460.       <p>The <a id="mapfunc" name="mapfunc"><em>MapName</em></a> is
  461.       the name of the map and will be used to specify a
  462.       mapping-function for the substitution strings of a rewriting
  463.       rule via one of the following constructs:</p>
  464.  
  465.       <p class="indent">
  466.         <strong><code>${</code> <em>MapName</em> <code>:</code>
  467.         <em>LookupKey</em> <code>}</code><br />
  468.          <code>${</code> <em>MapName</em> <code>:</code>
  469.         <em>LookupKey</em> <code>|</code> <em>DefaultValue</em>
  470.         <code>}</code></strong>
  471.       </p>
  472.  
  473.       <p>When such a construct occurs the map <em>MapName</em> is
  474.       consulted and the key <em>LookupKey</em> is looked-up. If the
  475.       key is found, the map-function construct is substituted by
  476.       <em>SubstValue</em>. If the key is not found then it is
  477.       substituted by <em>DefaultValue</em> or by the empty string
  478.       if no <em>DefaultValue</em> was specified.</p>
  479.  
  480.       <p>The following combinations for <em>MapType</em> and
  481.       <em>MapSource</em> can be used:</p>
  482.  
  483.       <ul>
  484.         <li>
  485.           <strong>Standard Plain Text</strong><br />
  486.            MapType: <code>txt</code>, MapSource: Unix filesystem
  487.           path to valid regular file 
  488.  
  489.           <p>This is the standard rewriting map feature where the
  490.           <em>MapSource</em> is a plain ASCII file containing
  491.           either blank lines, comment lines (starting with a '#'
  492.           character) or pairs like the following - one per
  493.           line.</p>
  494.  
  495.           <p class="indent">
  496.             <strong><em>MatchingKey</em>
  497.             <em>SubstValue</em></strong>
  498.           </p>
  499.  
  500. <example><title>Example</title>
  501. <pre>
  502. ##
  503. ##  map.txt -- rewriting map
  504. ##
  505.  
  506. Ralf.S.Engelschall    rse   # Bastard Operator From Hell
  507. Mr.Joe.Average        joe   # Mr. Average
  508. </pre>
  509. </example>
  510.  
  511. <example>
  512. RewriteMap real-to-user txt:/path/to/file/map.txt
  513. </example>
  514.         </li>
  515.  
  516.         <li>
  517.           <strong>Randomized Plain Text</strong><br />
  518.            MapType: <code>rnd</code>, MapSource: Unix filesystem
  519.           path to valid regular file 
  520.  
  521.           <p>This is identical to the Standard Plain Text variant
  522.           above but with a special post-processing feature: After
  523.           looking up a value it is parsed according to contained
  524.           ``<code>|</code>'' characters which have the meaning of
  525.           ``or''. In other words they indicate a set of
  526.           alternatives from which the actual returned value is
  527.           chosen randomly. Although this sounds crazy and useless,
  528.           it was actually designed for load balancing in a reverse
  529.           proxy situation where the looked up values are server
  530.           names. Example:</p>
  531.  
  532. <example>
  533. <pre>
  534. ##
  535. ##  map.txt -- rewriting map
  536. ##
  537.  
  538. static   www1|www2|www3|www4
  539. dynamic  www5|www6
  540. </pre>
  541. </example>
  542.  
  543. <example>
  544. RewriteMap servers rnd:/path/to/file/map.txt
  545. </example>
  546.         </li>
  547.  
  548.         <li>
  549.           <strong>Hash File</strong><br /> MapType:
  550.           <code>dbm[=<em>type</em>]</code>, MapSource: Unix filesystem
  551.           path to valid regular file
  552.  
  553.           <p>Here the source is a binary format DBM file containing
  554.           the same contents as a <em>Plain Text</em> format file, but
  555.           in a special representation which is optimized for really
  556.           fast lookups. The <em>type</em> can be sdbm, gdbm, ndbm, or
  557.           db depending on <a href="../install.html#dbm">compile-time
  558.           settings</a>.  If the <em>type</em> is ommitted, the
  559.           compile-time default will be chosen. You can create such a
  560.           file with any DBM tool or with the following Perl
  561.           script.  Be sure to adjust it to create the appropriate
  562.           type of DBM.  The example creates an NDBM file.</p>
  563.  
  564. <example>
  565. <pre>
  566. #!/path/to/bin/perl
  567. ##
  568. ##  txt2dbm -- convert txt map to dbm format
  569. ##
  570.  
  571. use NDBM_File;
  572. use Fcntl;
  573.  
  574. ($txtmap, $dbmmap) = @ARGV;
  575.  
  576. open(TXT, "<$txtmap") or die "Couldn't open $txtmap!\n";
  577. tie (%DB, 'NDBM_File', $dbmmap,O_RDWR|O_TRUNC|O_CREAT, 0644)
  578.   or die "Couldn't create $dbmmap!\n";
  579.  
  580. while (<TXT>) {
  581.   next if (/^\s*#/ or /^\s*$/);
  582.   $DB{$1} = $2 if (/^\s*(\S+)\s+(\S+)/);
  583. }
  584.  
  585. untie %DB;
  586. close(TXT);
  587. </pre>
  588. </example>
  589.  
  590. <example>
  591. $ txt2dbm map.txt map.db
  592. </example>
  593.         </li>
  594.  
  595.         <li>
  596.           <strong>Internal Function</strong><br />
  597.            MapType: <code>int</code>, MapSource: Internal Apache
  598.           function 
  599.  
  600.           <p>Here the source is an internal Apache function.
  601.           Currently you cannot create your own, but the following
  602.           functions already exists:</p>
  603.  
  604.           <ul>
  605.             <li><strong>toupper</strong>:<br />
  606.              Converts the looked up key to all upper case.</li>
  607.  
  608.             <li><strong>tolower</strong>:<br />
  609.              Converts the looked up key to all lower case.</li>
  610.  
  611.             <li><strong>escape</strong>:<br />
  612.              Translates special characters in the looked up key to
  613.             hex-encodings.</li>
  614.  
  615.             <li><strong>unescape</strong>:<br />
  616.              Translates hex-encodings in the looked up key back to
  617.             special characters.</li>
  618.           </ul>
  619.         </li>
  620.  
  621.         <li>
  622.           <strong>External Rewriting Program</strong><br />
  623.            MapType: <code>prg</code>, MapSource: Unix filesystem
  624.           path to valid regular file 
  625.  
  626.           <p>Here the source is a program, not a map file. To
  627.           create it you can use the language of your choice, but
  628.           the result has to be a executable (<em>i.e.</em>, either
  629.           object-code or a script with the magic cookie trick
  630.           '<code>#!/path/to/interpreter</code>' as the first
  631.           line).</p>
  632.  
  633.           <p>This program is started once at startup of the Apache
  634.           servers and then communicates with the rewriting engine
  635.           over its <code>stdin</code> and <code>stdout</code>
  636.           file-handles. For each map-function lookup it will
  637.           receive the key to lookup as a newline-terminated string
  638.           on <code>stdin</code>. It then has to give back the
  639.           looked-up value as a newline-terminated string on
  640.           <code>stdout</code> or the four-character string
  641.           ``<code>NULL</code>'' if it fails (<em>i.e.</em>, there
  642.           is no corresponding value for the given key). A trivial
  643.           program which will implement a 1:1 map (<em>i.e.</em>,
  644.           key == value) could be:</p>
  645.  
  646. <example>
  647. <pre>
  648. #!/usr/bin/perl
  649. $| = 1;
  650. while (<STDIN>) {
  651.     # ...put here any transformations or lookups...
  652.     print $_;
  653. }
  654. </pre>
  655. </example>
  656.  
  657.           <p>But be very careful:</p>
  658.  
  659.           <ol>
  660.             <li>``<em>Keep it simple, stupid</em>'' (KISS), because
  661.             if this program hangs it will hang the Apache server
  662.             when the rule occurs.</li>
  663.  
  664.             <li>Avoid one common mistake: never do buffered I/O on
  665.             <code>stdout</code>! This will cause a deadloop! Hence
  666.             the ``<code>$|=1</code>'' in the above example...</li>
  667.  
  668.             <li>Use the <directive
  669.             module="mod_rewrite">RewriteLock</directive> directive to
  670.             define a lockfile mod_rewrite can use to synchronize the
  671.             communication to the program. By default no such
  672.             synchronization takes place.</li>
  673.           </ol>
  674.         </li>
  675.       </ul>
  676.       <p>The <directive>RewriteMap</directive> directive can occur more than
  677.       once. For each mapping-function use one
  678.       <directive>RewriteMap</directive> directive to declare its rewriting
  679.       mapfile. While you cannot <strong>declare</strong> a map in
  680.       per-directory context it is of course possible to
  681.       <strong>use</strong> this map in per-directory context. </p>
  682.  
  683. <note><title>Note</title> For plain text and DBM format files the
  684. looked-up keys are cached in-core until the <code>mtime</code> of the
  685. mapfile changes or the server does a restart. This way you can have
  686. map-functions in rules which are used for <strong>every</strong>
  687. request.  This is no problem, because the external lookup only happens
  688. once!
  689. </note>
  690.  
  691. </usage>
  692. </directivesynopsis>
  693.  
  694. <directivesynopsis>
  695. <name>RewriteBase</name>
  696. <description>Sets the base URL for per-directory rewrites</description>
  697. <syntax>RewriteBase <em>URL-path</em></syntax>
  698. <default>See usage for information.</default>
  699. <contextlist><context>directory</context><context>.htaccess</context>
  700. </contextlist>
  701. <override>FileInfo</override>
  702.  
  703. <usage>
  704.       <p>The <directive>RewriteBase</directive> directive explicitly
  705.       sets the base URL for per-directory rewrites. As you will see
  706.       below, <directive module="mod_rewrite">RewriteRule</directive>
  707.       can be used in per-directory config files
  708.       (<code>.htaccess</code>). There it will act locally,
  709.       <em>i.e.</em>, the local directory prefix is stripped at this
  710.       stage of processing and your rewriting rules act only on the
  711.       remainder. At the end it is automatically added back to the
  712.       path. The default setting is; <directive>RewriteBase</directive> <em>physical-directory-path</em></p>
  713.  
  714.       <p>When a substitution occurs for a new URL, this module has
  715.       to re-inject the URL into the server processing. To be able
  716.       to do this it needs to know what the corresponding URL-prefix
  717.       or URL-base is. By default this prefix is the corresponding
  718.       filepath itself. <strong>But at most websites URLs are NOT
  719.       directly related to physical filename paths, so this
  720.       assumption will usually be wrong!</strong> There you have to
  721.       use the <code>RewriteBase</code> directive to specify the
  722.       correct URL-prefix.</p>
  723.  
  724. <note> If your webserver's URLs are <strong>not</strong> directly
  725. related to physical file paths, you have to use
  726. <directive>RewriteBase</directive> in every <code>.htaccess</code>
  727. files where you want to use <directive
  728. module="mod_rewrite">RewriteRule</directive> directives.
  729. </note>
  730.  
  731.         <p> For example, assume the following per-directory config file:</p>
  732.  
  733. <example>
  734. <pre>
  735. #
  736. #  /abc/def/.htaccess -- per-dir config file for directory /abc/def
  737. #  Remember: /abc/def is the physical path of /xyz, <em>i.e.</em>, the server
  738. #            has a 'Alias /xyz /abc/def' directive <em>e.g.</em>
  739. #
  740.  
  741. RewriteEngine On
  742.  
  743. #  let the server know that we were reached via /xyz and not
  744. #  via the physical path prefix /abc/def
  745. RewriteBase   /xyz
  746.  
  747. #  now the rewriting rules
  748. RewriteRule   ^oldstuff\.html$  newstuff.html
  749. </pre>
  750. </example>
  751.  
  752.         <p>In the above example, a request to
  753.         <code>/xyz/oldstuff.html</code> gets correctly rewritten to
  754.         the physical file <code>/abc/def/newstuff.html</code>.</p>
  755.  
  756. <note><title>For Apache Hackers</title>
  757. <p>The following list gives detailed information about
  758.               the internal processing steps:</p>
  759. <pre>
  760. Request:
  761.   /xyz/oldstuff.html
  762.  
  763. Internal Processing:
  764.   /xyz/oldstuff.html     -> /abc/def/oldstuff.html  (per-server Alias)
  765.   /abc/def/oldstuff.html -> /abc/def/newstuff.html  (per-dir    RewriteRule)
  766.   /abc/def/newstuff.html -> /xyz/newstuff.html      (per-dir    RewriteBase)
  767.   /xyz/newstuff.html     -> /abc/def/newstuff.html  (per-server Alias)
  768.  
  769. Result:
  770.   /abc/def/newstuff.html
  771. </pre>
  772.               <p>This seems very complicated but is
  773.               the correct Apache internal processing, because the
  774.               per-directory rewriting comes too late in the
  775.               process. So, when it occurs the (rewritten) request
  776.               has to be re-injected into the Apache kernel! BUT:
  777.               While this seems like a serious overhead, it really
  778.               isn't, because this re-injection happens fully
  779.               internally to the Apache server and the same
  780.               procedure is used by many other operations inside
  781.               Apache. So, you can be sure the design and
  782.               implementation is correct.</p>
  783. </note>
  784.  
  785. </usage>
  786.  
  787. </directivesynopsis>
  788.  
  789. <directivesynopsis>
  790. <name>RewriteCond</name>
  791. <description>Defines a condition under which rewriting will take place
  792. </description>
  793. <syntax> RewriteCond
  794.       <em>TestString</em> <em>CondPattern</em></syntax>
  795. <contextlist><context>server config</context><context>virtual host</context>
  796. <context>directory</context><context>.htaccess</context></contextlist>
  797. <override>FileInfo</override>
  798.  
  799. <usage>
  800.       <p>The <directive>RewriteCond</directive> directive defines a
  801.       rule condition. Precede a <directive
  802.       module="mod_rewrite">RewriteRule</directive> directive with one
  803.       or more <directive>RewriteCond</directive> directives. The following
  804.       rewriting rule is only used if its pattern matches the current
  805.       state of the URI <strong>and</strong> if these additional
  806.       conditions apply too.</p>
  807.  
  808.       <p><em>TestString</em> is a string which can contains the
  809.       following expanded constructs in addition to plain text:</p>
  810.  
  811.       <ul>
  812.         <li>
  813.           <strong>RewriteRule backreferences</strong>: These are
  814.           backreferences of the form 
  815.  
  816.           <p class="indent">
  817.             <strong><code>$N</code></strong>
  818.           </p>
  819.           (0 <= N <= 9) which provide access to the grouped
  820.           parts (parenthesis!) of the pattern from the
  821.           corresponding <code>RewriteRule</code> directive (the one
  822.           following the current bunch of <code>RewriteCond</code>
  823.           directives).
  824.         </li>
  825.  
  826.         <li>
  827.           <strong>RewriteCond backreferences</strong>: These are
  828.           backreferences of the form 
  829.  
  830.           <p class="indent">
  831.             <strong><code>%N</code></strong>
  832.           </p>
  833.           (1 <= N <= 9) which provide access to the grouped
  834.           parts (parentheses!) of the pattern from the last matched
  835.           <code>RewriteCond</code> directive in the current bunch
  836.           of conditions.
  837.         </li>
  838.  
  839.         <li>
  840.           <strong>RewriteMap expansions</strong>: These are
  841.           expansions of the form 
  842.  
  843.           <p class="indent">
  844.             <strong><code>${mapname:key|default}</code></strong>
  845.           </p>
  846.           See <a href="#mapfunc">the documentation for
  847.           RewriteMap</a> for more details.
  848.         </li>
  849.  
  850.         <li>
  851.           <strong>Server-Variables</strong>: These are variables of
  852.           the form 
  853.  
  854.           <p class="indent">
  855.             <strong><code>%{</code> <em>NAME_OF_VARIABLE</em>
  856.             <code>}</code></strong>
  857.           </p>
  858.           where <em>NAME_OF_VARIABLE</em> can be a string taken
  859.           from the following list: 
  860.  
  861.           <table>
  862.             <tr>
  863.               <th>HTTP headers:</th> <th>connection & request:</th> <th></th>
  864.         </tr>
  865.  
  866.             <tr>
  867.           <td>
  868.          HTTP_USER_AGENT<br />
  869.                  HTTP_REFERER<br />
  870.                  HTTP_COOKIE<br />
  871.                  HTTP_FORWARDED<br />
  872.                  HTTP_HOST<br />
  873.                  HTTP_PROXY_CONNECTION<br />
  874.                  HTTP_ACCEPT<br />
  875.               </td>
  876.  
  877.               <td>
  878.                  REMOTE_ADDR<br />
  879.                  REMOTE_HOST<br />
  880.                  REMOTE_USER<br />
  881.                  REMOTE_IDENT<br />
  882.                  REQUEST_METHOD<br />
  883.                  SCRIPT_FILENAME<br />
  884.                  PATH_INFO<br />
  885.                  QUERY_STRING<br />
  886.                  AUTH_TYPE<br />
  887.               </td>
  888.           
  889.           <td></td>
  890.             </tr>
  891.  
  892.             <tr>
  893.               <th>server internals:</th> <th>system stuff:</th> <th>specials:</th>
  894.         </tr>
  895.  
  896.             <tr>
  897.           <td>
  898.              DOCUMENT_ROOT<br />
  899.                  SERVER_ADMIN<br />
  900.                  SERVER_NAME<br />
  901.                  SERVER_ADDR<br />
  902.                  SERVER_PORT<br />
  903.                  SERVER_PROTOCOL<br />
  904.                  SERVER_SOFTWARE<br />
  905.               </td>
  906.  
  907.               <td>
  908.                  TIME_YEAR<br />
  909.                  TIME_MON<br />
  910.                  TIME_DAY<br />
  911.                  TIME_HOUR<br />
  912.                  TIME_MIN<br />
  913.                  TIME_SEC<br />
  914.                  TIME_WDAY<br />
  915.                  TIME<br />
  916.               </td>
  917.  
  918.               <td>
  919.                  API_VERSION<br />
  920.                  THE_REQUEST<br />
  921.                  REQUEST_URI<br />
  922.                  REQUEST_FILENAME<br />
  923.                  IS_SUBREQ<br />
  924.               </td>
  925.             </tr>
  926.           </table>
  927.  
  928. <note>
  929.                 <p>These variables all
  930.                 correspond to the similarly named HTTP
  931.                 MIME-headers, C variables of the Apache server or
  932.                 <code>struct tm</code> fields of the Unix system.
  933.                 Most are documented elsewhere in the Manual or in
  934.                 the CGI specification. Those that are special to
  935.                 mod_rewrite include:</p>
  936.  
  937.                 <dl>
  938.                   <dt><code>IS_SUBREQ</code></dt>
  939.  
  940.                   <dd>Will contain the text "true" if the request
  941.                   currently being processed is a sub-request,
  942.                   "false" otherwise. Sub-requests may be generated
  943.                   by modules that need to resolve additional files
  944.                   or URIs in order to complete their tasks.</dd>
  945.  
  946.                   <dt><code>API_VERSION</code></dt>
  947.  
  948.                   <dd>This is the version of the Apache module API
  949.                   (the internal interface between server and
  950.                   module) in the current httpd build, as defined in
  951.                   include/ap_mmn.h. The module API version
  952.                   corresponds to the version of Apache in use (in
  953.                   the release version of Apache 1.3.14, for
  954.                   instance, it is 19990320:10), but is mainly of
  955.                   interest to module authors.</dd>
  956.  
  957.                   <dt><code>THE_REQUEST</code></dt>
  958.  
  959.                   <dd>The full HTTP request line sent by the
  960.                   browser to the server (e.g., "<code>GET
  961.                   /index.html HTTP/1.1</code>"). This does not
  962.                   include any additional headers sent by the
  963.                   browser.</dd>
  964.  
  965.                   <dt><code>REQUEST_URI</code></dt>
  966.  
  967.                   <dd>The resource requested in the HTTP request
  968.                   line. (In the example above, this would be
  969.                   "/index.html".)</dd>
  970.  
  971.                   <dt><code>REQUEST_FILENAME</code></dt>
  972.  
  973.                   <dd>The full local filesystem path to the file or
  974.                   script matching the request.</dd>
  975.                 </dl>
  976. </note>
  977.         </li>
  978.       </ul>
  979.  
  980.       <p>Special Notes:</p>
  981.  
  982.       <ol>
  983.         <li>The variables SCRIPT_FILENAME and REQUEST_FILENAME
  984.         contain the same value, <em>i.e.</em>, the value of the
  985.         <code>filename</code> field of the internal
  986.         <code>request_rec</code> structure of the Apache server.
  987.         The first name is just the commonly known CGI variable name
  988.         while the second is the consistent counterpart to
  989.         REQUEST_URI (which contains the value of the
  990.         <code>uri</code> field of <code>request_rec</code>).</li>
  991.  
  992.         <li>There is the special format:
  993.         <code>%{ENV:variable}</code> where <em>variable</em> can be
  994.         any environment variable. This is looked-up via internal
  995.         Apache structures and (if not found there) via
  996.         <code>getenv()</code> from the Apache server process.</li>
  997.  
  998.         <li>There is the special format:
  999.         <code>%{HTTP:header}</code> where <em>header</em> can be
  1000.         any HTTP MIME-header name. This is looked-up from the HTTP
  1001.         request. Example: <code>%{HTTP:Proxy-Connection}</code> is
  1002.         the value of the HTTP header
  1003.         ``<code>Proxy-Connection:</code>''.</li>
  1004.  
  1005.         <li>There is the special format
  1006.         <code>%{LA-U:variable}</code> for look-aheads which perform
  1007.         an internal (URL-based) sub-request to determine the final
  1008.         value of <em>variable</em>. Use this when you want to use a
  1009.         variable for rewriting which is actually set later in an
  1010.         API phase and thus is not available at the current stage.
  1011.         For instance when you want to rewrite according to the
  1012.         <code>REMOTE_USER</code> variable from within the
  1013.         per-server context (<code>httpd.conf</code> file) you have
  1014.         to use <code>%{LA-U:REMOTE_USER}</code> because this
  1015.         variable is set by the authorization phases which come
  1016.         <em>after</em> the URL translation phase where mod_rewrite
  1017.         operates. On the other hand, because mod_rewrite implements
  1018.         its per-directory context (<code>.htaccess</code> file) via
  1019.         the Fixup phase of the API and because the authorization
  1020.         phases come <em>before</em> this phase, you just can use
  1021.         <code>%{REMOTE_USER}</code> there.</li>
  1022.  
  1023.         <li>There is the special format:
  1024.         <code>%{LA-F:variable}</code> which performs an internal
  1025.         (filename-based) sub-request to determine the final value
  1026.         of <em>variable</em>. Most of the time this is the same as
  1027.         LA-U above.</li>
  1028.       </ol>
  1029.  
  1030.       <p><em>CondPattern</em> is the condition pattern,
  1031.       <em>i.e.</em>, a regular expression which is applied to the
  1032.       current instance of the <em>TestString</em>, <em>i.e.</em>,
  1033.       <em>TestString</em> is evaluated and then matched against
  1034.       <em>CondPattern</em>.</p>
  1035.  
  1036.       <p><strong>Remember:</strong> <em>CondPattern</em> is a
  1037.       <em>perl compatible regular expression</em> with some
  1038.       additions:</p>
  1039.  
  1040.       <ol>
  1041.         <li>You can prefix the pattern string with a
  1042.         '<code>!</code>' character (exclamation mark) to specify a
  1043.         <strong>non</strong>-matching pattern.</li>
  1044.  
  1045.         <li>
  1046.           There are some special variants of <em>CondPatterns</em>.
  1047.           Instead of real regular expression strings you can also
  1048.           use one of the following: 
  1049.  
  1050.           <ul>
  1051.             <li>'<strong><CondPattern</strong>' (is lexically
  1052.             lower)<br />
  1053.              Treats the <em>CondPattern</em> as a plain string and
  1054.             compares it lexically to <em>TestString</em>. True if
  1055.             <em>TestString</em> is lexically lower than
  1056.             <em>CondPattern</em>.</li>
  1057.  
  1058.             <li>'<strong>>CondPattern</strong>' (is lexically
  1059.             greater)<br />
  1060.              Treats the <em>CondPattern</em> as a plain string and
  1061.             compares it lexically to <em>TestString</em>. True if
  1062.             <em>TestString</em> is lexically greater than
  1063.             <em>CondPattern</em>.</li>
  1064.  
  1065.             <li>'<strong>=CondPattern</strong>' (is lexically
  1066.             equal)<br />
  1067.              Treats the <em>CondPattern</em> as a plain string and
  1068.             compares it lexically to <em>TestString</em>. True if
  1069.             <em>TestString</em> is lexically equal to
  1070.             <em>CondPattern</em>, i.e the two strings are exactly
  1071.             equal (character by character). If <em>CondPattern</em>
  1072.             is just <code>""</code> (two quotation marks) this
  1073.             compares <em>TestString</em> to the empty string.</li>
  1074.  
  1075.             <li>'<strong>-d</strong>' (is
  1076.             <strong>d</strong>irectory)<br />
  1077.              Treats the <em>TestString</em> as a pathname and tests
  1078.             if it exists and is a directory.</li>
  1079.  
  1080.             <li>'<strong>-f</strong>' (is regular
  1081.             <strong>f</strong>ile)<br />
  1082.              Treats the <em>TestString</em> as a pathname and tests
  1083.             if it exists and is a regular file.</li>
  1084.  
  1085.             <li>'<strong>-s</strong>' (is regular file with
  1086.             <strong>s</strong>ize)<br />
  1087.              Treats the <em>TestString</em> as a pathname and tests
  1088.             if it exists and is a regular file with size greater
  1089.             than zero.</li>
  1090.  
  1091.             <li>'<strong>-l</strong>' (is symbolic
  1092.             <strong>l</strong>ink)<br />
  1093.              Treats the <em>TestString</em> as a pathname and tests
  1094.             if it exists and is a symbolic link.</li>
  1095.  
  1096.             <li>'<strong>-F</strong>' (is existing file via
  1097.             subrequest)<br />
  1098.              Checks if <em>TestString</em> is a valid file and
  1099.             accessible via all the server's currently-configured
  1100.             access controls for that path. This uses an internal
  1101.             subrequest to determine the check, so use it with care
  1102.             because it decreases your servers performance!</li>
  1103.  
  1104.             <li>'<strong>-U</strong>' (is existing URL via
  1105.             subrequest)<br />
  1106.              Checks if <em>TestString</em> is a valid URL and
  1107.             accessible via all the server's currently-configured
  1108.             access controls for that path. This uses an internal
  1109.             subrequest to determine the check, so use it with care
  1110.             because it decreases your server's performance!</li>
  1111.           </ul>
  1112.  
  1113. <note><title>Notice</title>
  1114.               All of these tests can
  1115.               also be prefixed by an exclamation mark ('!') to
  1116.               negate their meaning.
  1117. </note>
  1118.         </li>
  1119.       </ol>
  1120.  
  1121.       <p>Additionally you can set special flags for
  1122.       <em>CondPattern</em> by appending</p>
  1123.  
  1124.       <p class="indent">
  1125.         <strong><code>[</code><em>flags</em><code>]</code></strong>
  1126.       </p>
  1127.  
  1128.       <p>as the third argument to the <code>RewriteCond</code>
  1129.       directive. <em>Flags</em> is a comma-separated list of the
  1130.       following flags:</p>
  1131.  
  1132.       <ul>
  1133.         <li>'<strong><code>nocase|NC</code></strong>'
  1134.         (<strong>n</strong>o <strong>c</strong>ase)<br />
  1135.          This makes the test case-insensitive, <em>i.e.</em>, there
  1136.         is no difference between 'A-Z' and 'a-z' both in the
  1137.         expanded <em>TestString</em> and the <em>CondPattern</em>.
  1138.         This flag is effective only for comparisons between
  1139.         <em>TestString</em> and <em>CondPattern</em>. It has no
  1140.         effect on filesystem and subrequest checks.</li>
  1141.  
  1142.         <li>
  1143.           '<strong><code>ornext|OR</code></strong>'
  1144.           (<strong>or</strong> next condition)<br />
  1145.            Use this to combine rule conditions with a local OR
  1146.           instead of the implicit AND. Typical example: 
  1147.  
  1148. <example>
  1149. <pre>
  1150. RewriteCond %{REMOTE_HOST}  ^host1.*  [OR]
  1151. RewriteCond %{REMOTE_HOST}  ^host2.*  [OR]
  1152. RewriteCond %{REMOTE_HOST}  ^host3.*
  1153. RewriteRule ...some special stuff for any of these hosts...
  1154. </pre>
  1155. </example>
  1156.  
  1157.           Without this flag you would have to write the cond/rule
  1158.           three times.
  1159.         </li>
  1160.       </ul>
  1161.  
  1162.       <p><strong>Example:</strong></p>
  1163.  
  1164.        <p>To rewrite the Homepage of a site according to the
  1165.         ``<code>User-Agent:</code>'' header of the request, you can
  1166.         use the following: </p>
  1167.  
  1168. <example>
  1169. <pre>
  1170. RewriteCond  %{HTTP_USER_AGENT}  ^Mozilla.*
  1171. RewriteRule  ^/$                 /homepage.max.html  [L]
  1172.  
  1173. RewriteCond  %{HTTP_USER_AGENT}  ^Lynx.*
  1174. RewriteRule  ^/$                 /homepage.min.html  [L]
  1175.  
  1176. RewriteRule  ^/$                 /homepage.std.html  [L]
  1177. </pre>
  1178. </example>
  1179.  
  1180.         <p>Interpretation: If you use Netscape Navigator as your
  1181.         browser (which identifies itself as 'Mozilla'), then you
  1182.         get the max homepage, which includes Frames, <em>etc.</em>
  1183.         If you use the Lynx browser (which is Terminal-based), then
  1184.         you get the min homepage, which contains no images, no
  1185.         tables, <em>etc.</em> If you use any other browser you get
  1186.         the standard homepage.</p>
  1187.  
  1188. </usage>
  1189.  
  1190. </directivesynopsis>
  1191.  
  1192. <directivesynopsis>
  1193. <name>RewriteRule</name>
  1194. <description>Defines rules for the rewriting engine</description>
  1195. <syntax>RewriteRule
  1196.       <em>Pattern</em> <em>Substitution</em></syntax>
  1197. <contextlist><context>server config</context><context>virtual host</context>
  1198. <context>directory</context><context>.htaccess</context></contextlist>
  1199. <override>FileInfo</override>
  1200. <compatibility>The cookie-flag is available in Apache 2.0.40 and later.</compatibility>
  1201.  
  1202. <usage>
  1203.       <p>The <directive>RewriteRule</directive> directive is the real
  1204.       rewriting workhorse. The directive can occur more than once.
  1205.       Each directive then defines one single rewriting rule. The
  1206.       <strong>definition order</strong> of these rules is
  1207.       <strong>important</strong>, because this order is used when
  1208.       applying the rules at run-time.</p>
  1209.  
  1210.       <p><a id="patterns" name="patterns"><em>Pattern</em></a> is
  1211.       a perl compatible <a id="regexp" name="regexp">regular
  1212.       expression</a> which gets applied to the current URL. Here
  1213.       ``current'' means the value of the URL when this rule gets
  1214.       applied. This may not be the originally requested URL,
  1215.       because any number of rules may already have matched and made
  1216.       alterations to it.</p>
  1217.  
  1218.       <p>Some hints about the syntax of regular expressions:</p>
  1219.  
  1220. <note><pre>
  1221. <strong>Text:</strong>
  1222.   <strong><code>.</code></strong>           Any single character
  1223.   <strong><code>[</code></strong>chars<strong><code>]</code></strong>     Character class: One  of chars
  1224.   <strong><code>[^</code></strong>chars<strong><code>]</code></strong>    Character class: None of chars
  1225.   text1<strong><code>|</code></strong>text2 Alternative: text1 or text2
  1226.  
  1227. <strong>Quantifiers:</strong>
  1228.   <strong><code>?</code></strong>           0 or 1 of the preceding text
  1229.   <strong><code>*</code></strong>           0 or N of the preceding text (N > 0)
  1230.   <strong><code>+</code></strong>           1 or N of the preceding text (N > 1)
  1231.  
  1232. <strong>Grouping:</strong>
  1233.   <strong><code>(</code></strong>text<strong><code>)</code></strong>      Grouping of text
  1234.               (either to set the borders of an alternative or
  1235.               for making backreferences where the <strong>N</strong>th group can 
  1236.               be used on the RHS of a RewriteRule with <code>$</code><strong>N</strong>)
  1237.  
  1238. <strong>Anchors:</strong>
  1239.   <strong><code>^</code></strong>           Start of line anchor
  1240.   <strong><code>$</code></strong>           End   of line anchor
  1241.  
  1242. <strong>Escaping:</strong>
  1243.   <strong><code>\</code></strong>char       escape that particular char
  1244.               (for instance to specify the chars "<code>.[]()</code>" <em>etc.</em>)
  1245. </pre></note>
  1246.  
  1247.       <p>For more information about regular expressions have a look at the
  1248.       perl regular expression manpage ("<a
  1249.       href="http://www.perldoc.com/perl5.6.1/pod/perlre.html">perldoc
  1250.       perlre</a>"). If you are interested in more detailed
  1251.       information about regular expressions and their variants
  1252.       (POSIX regex <em>etc.</em>) have a look at the
  1253.       following dedicated book on this topic:</p>
  1254.  
  1255.       <p class="indent">
  1256.         <em>Mastering Regular Expressions</em><br />
  1257.          Jeffrey E.F. Friedl<br />
  1258.          Nutshell Handbook Series<br />
  1259.          O'Reilly & Associates, Inc. 1997<br />
  1260.          ISBN 1-56592-257-3<br />
  1261.       </p>
  1262.  
  1263.       <p>Additionally in mod_rewrite the NOT character
  1264.       ('<code>!</code>') is a possible pattern prefix. This gives
  1265.       you the ability to negate a pattern; to say, for instance:
  1266.       ``<em>if the current URL does <strong>NOT</strong> match this
  1267.       pattern</em>''. This can be used for exceptional cases, where
  1268.       it is easier to match the negative pattern, or as a last
  1269.       default rule.</p>
  1270.  
  1271. <note><title>Notice</title>
  1272. When using the NOT character
  1273.           to negate a pattern you cannot have grouped wildcard
  1274.           parts in the pattern. This is impossible because when the
  1275.           pattern does NOT match, there are no contents for the
  1276.           groups. In consequence, if negated patterns are used, you
  1277.           cannot use <code>$N</code> in the substitution
  1278.           string!
  1279. </note>
  1280.  
  1281.       <p><a id="rhs" name="rhs"><em>Substitution</em></a> of a
  1282.       rewriting rule is the string which is substituted for (or
  1283.       replaces) the original URL for which <em>Pattern</em>
  1284.       matched. Beside plain text you can use</p>
  1285.  
  1286.       <ol>
  1287.         <li>back-references <code>$N</code> to the RewriteRule
  1288.         pattern</li>
  1289.  
  1290.         <li>back-references <code>%N</code> to the last matched
  1291.         RewriteCond pattern</li>
  1292.  
  1293.         <li>server-variables as in rule condition test-strings
  1294.         (<code>%{VARNAME}</code>)</li>
  1295.  
  1296.         <li><a href="#mapfunc">mapping-function</a> calls
  1297.         (<code>${mapname:key|default}</code>)</li>
  1298.       </ol>
  1299.       <p>Back-references are <code>$</code><strong>N</strong>
  1300.       (<strong>N</strong>=0..9) identifiers which will be replaced
  1301.       by the contents of the <strong>N</strong>th group of the
  1302.       matched <em>Pattern</em>. The server-variables are the same
  1303.       as for the <em>TestString</em> of a <code>RewriteCond</code>
  1304.       directive. The mapping-functions come from the
  1305.       <code>RewriteMap</code> directive and are explained there.
  1306.       These three types of variables are expanded in the order of
  1307.       the above list. </p>
  1308.  
  1309.       <p>As already mentioned above, all the rewriting rules are
  1310.       applied to the <em>Substitution</em> (in the order of
  1311.       definition in the config file). The URL is <strong>completely
  1312.       replaced</strong> by the <em>Substitution</em> and the
  1313.       rewriting process goes on until there are no more rules
  1314.       unless explicitly terminated by a
  1315.       <code><strong>L</strong></code> flag - see below.</p>
  1316.  
  1317.       <p>There is a special substitution string named
  1318.       '<code>-</code>' which means: <strong>NO
  1319.       substitution</strong>! Sounds silly? No, it is useful to
  1320.       provide rewriting rules which <strong>only</strong> match
  1321.       some URLs but do no substitution, <em>e.g.</em>, in
  1322.       conjunction with the <strong>C</strong> (chain) flag to be
  1323.       able to have more than one pattern to be applied before a
  1324.       substitution occurs.</p>
  1325.  
  1326.       <p>One more note: You can even create URLs in the
  1327.       substitution string containing a query string part. Just use
  1328.       a question mark inside the substitution string to indicate
  1329.       that the following stuff should be re-injected into the
  1330.       QUERY_STRING. When you want to erase an existing query
  1331.       string, end the substitution string with just the question
  1332.       mark.</p>
  1333.  
  1334. <note><title>Note</title>
  1335. There is a special feature:
  1336.           When you prefix a substitution field with
  1337.           <code>http://</code><em>thishost</em>[<em>:thisport</em>]
  1338.           then <strong>mod_rewrite</strong> automatically strips it
  1339.           out. This auto-reduction on implicit external redirect
  1340.           URLs is a useful and important feature when used in
  1341.           combination with a mapping-function which generates the
  1342.           hostname part. Have a look at the first example in the
  1343.           example section below to understand this.
  1344. </note>
  1345.  
  1346. <note><title>Remember</title>
  1347.  An unconditional external
  1348.           redirect to your own server will not work with the prefix
  1349.           <code>http://thishost</code> because of this feature. To
  1350.           achieve such a self-redirect, you have to use the
  1351.           <strong>R</strong>-flag (see below).
  1352. </note>
  1353.  
  1354.       <p>Additionally you can set special flags for
  1355.       <em>Substitution</em> by appending</p>
  1356.  
  1357.       <p class="indent">
  1358.         <strong><code>[</code><em>flags</em><code>]</code></strong>
  1359.       </p>
  1360.       <p>
  1361.       as the third argument to the <code>RewriteRule</code>
  1362.       directive. <em>Flags</em> is a comma-separated list of the
  1363.       following flags: </p>
  1364.  
  1365.       <ul>
  1366.         <li>
  1367.           '<strong><code>redirect|R</code>
  1368.           [=<em>code</em>]</strong>' (force <a id="redirect"
  1369.           name="redirect"><strong>r</strong>edirect</a>)<br />
  1370.            Prefix <em>Substitution</em> with
  1371.           <code>http://thishost[:thisport]/</code> (which makes the
  1372.           new URL a URI) to force a external redirection. If no
  1373.           <em>code</em> is given a HTTP response of 302 (MOVED
  1374.           TEMPORARILY) is used. If you want to use other response
  1375.           codes in the range 300-400 just specify them as a number
  1376.           or use one of the following symbolic names:
  1377.           <code>temp</code> (default), <code>permanent</code>,
  1378.           <code>seeother</code>. Use it for rules which should
  1379.           canonicalize the URL and give it back to the client,
  1380.           <em>e.g.</em>, translate ``<code>/~</code>'' into
  1381.           ``<code>/u/</code>'' or always append a slash to
  1382.           <code>/u/</code><em>user</em>, etc.<br />
  1383.            
  1384.  
  1385.           <p><strong>Note:</strong> When you use this flag, make
  1386.           sure that the substitution field is a valid URL! If not,
  1387.           you are redirecting to an invalid location! And remember
  1388.           that this flag itself only prefixes the URL with
  1389.           <code>http://thishost[:thisport]/</code>, rewriting
  1390.           continues. Usually you also want to stop and do the
  1391.           redirection immediately. To stop the rewriting you also
  1392.           have to provide the 'L' flag.</p>
  1393.         </li>
  1394.  
  1395.         <li>'<strong><code>forbidden|F</code></strong>' (force URL
  1396.         to be <strong>f</strong>orbidden)<br />
  1397.          This forces the current URL to be forbidden,
  1398.         <em>i.e.</em>, it immediately sends back a HTTP response of
  1399.         403 (FORBIDDEN). Use this flag in conjunction with
  1400.         appropriate RewriteConds to conditionally block some
  1401.         URLs.</li>
  1402.  
  1403.         <li>'<strong><code>gone|G</code></strong>' (force URL to be
  1404.         <strong>g</strong>one)<br />
  1405.          This forces the current URL to be gone, <em>i.e.</em>, it
  1406.         immediately sends back a HTTP response of 410 (GONE). Use
  1407.         this flag to mark pages which no longer exist as gone.</li>
  1408.  
  1409.         <li>
  1410.           '<strong><code>proxy|P</code></strong>' (force
  1411.           <strong>p</strong>roxy)<br />
  1412.            This flag forces the substitution part to be internally
  1413.           forced as a proxy request and immediately (<em>i.e.</em>,
  1414.           rewriting rule processing stops here) put through the <a
  1415.           href="mod_proxy.html">proxy module</a>. You have to make
  1416.           sure that the substitution string is a valid URI
  1417.           (<em>e.g.</em>, typically starting with
  1418.           <code>http://</code><em>hostname</em>) which can be
  1419.           handled by the Apache proxy module. If not you get an
  1420.           error from the proxy module. Use this flag to achieve a
  1421.           more powerful implementation of the <a
  1422.           href="mod_proxy.html#proxypass">ProxyPass</a> directive,
  1423.           to map some remote stuff into the namespace of the local
  1424.           server. 
  1425.  
  1426.           <p>Notice: To use this functionality make sure you have
  1427.           the proxy module compiled into your Apache server
  1428.           program. If you don't know please check whether
  1429.           <code>mod_proxy.c</code> is part of the ``<code>httpd
  1430.           -l</code>'' output. If yes, this functionality is
  1431.           available to mod_rewrite. If not, then you first have to
  1432.           rebuild the ``<code>httpd</code>'' program with mod_proxy
  1433.           enabled.</p>
  1434.         </li>
  1435.  
  1436.         <li>'<strong><code>last|L</code></strong>'
  1437.         (<strong>l</strong>ast rule)<br />
  1438.          Stop the rewriting process here and don't apply any more
  1439.         rewriting rules. This corresponds to the Perl
  1440.         <code>last</code> command or the <code>break</code> command
  1441.         from the C language. Use this flag to prevent the currently
  1442.         rewritten URL from being rewritten further by following
  1443.         rules. For example, use it to rewrite the root-path URL
  1444.         ('<code>/</code>') to a real one, <em>e.g.</em>,
  1445.         '<code>/e/www/</code>'.</li>
  1446.  
  1447.         <li>'<strong><code>next|N</code></strong>'
  1448.         (<strong>n</strong>ext round)<br />
  1449.          Re-run the rewriting process (starting again with the
  1450.         first rewriting rule). Here the URL to match is again not
  1451.         the original URL but the URL from the last rewriting rule.
  1452.         This corresponds to the Perl <code>next</code> command or
  1453.         the <code>continue</code> command from the C language. Use
  1454.         this flag to restart the rewriting process, <em>i.e.</em>,
  1455.         to immediately go to the top of the loop.<br />
  1456.          <strong>But be careful not to create an infinite
  1457.         loop!</strong></li>
  1458.  
  1459.         <li>'<strong><code>chain|C</code></strong>'
  1460.         (<strong>c</strong>hained with next rule)<br />
  1461.          This flag chains the current rule with the next rule
  1462.         (which itself can be chained with the following rule,
  1463.         <em>etc.</em>). This has the following effect: if a rule
  1464.         matches, then processing continues as usual, <em>i.e.</em>,
  1465.         the flag has no effect. If the rule does
  1466.         <strong>not</strong> match, then all following chained
  1467.         rules are skipped. For instance, use it to remove the
  1468.         ``<code>.www</code>'' part inside a per-directory rule set
  1469.         when you let an external redirect happen (where the
  1470.         ``<code>.www</code>'' part should not to occur!).</li>
  1471.  
  1472.         <li>
  1473.         '<strong><code>type|T</code></strong>=<em>MIME-type</em>'
  1474.         (force MIME <strong>t</strong>ype)<br />
  1475.          Force the MIME-type of the target file to be
  1476.         <em>MIME-type</em>. For instance, this can be used to
  1477.         simulate the <code>mod_alias</code> directive
  1478.         <code>ScriptAlias</code> which internally forces all files
  1479.         inside the mapped directory to have a MIME type of
  1480.         ``<code>application/x-httpd-cgi</code>''.</li>
  1481.  
  1482.         <li>
  1483.           '<strong><code>nosubreq|NS</code></strong>' (used only if
  1484.           <strong>n</strong>o internal
  1485.           <strong>s</strong>ub-request)<br />
  1486.            This flag forces the rewriting engine to skip a
  1487.           rewriting rule if the current request is an internal
  1488.           sub-request. For instance, sub-requests occur internally
  1489.           in Apache when <code>mod_include</code> tries to find out
  1490.           information about possible directory default files
  1491.           (<code>index.xxx</code>). On sub-requests it is not
  1492.           always useful and even sometimes causes a failure to if
  1493.           the complete set of rules are applied. Use this flag to
  1494.           exclude some rules.<br />
  1495.            
  1496.  
  1497.           <p>Use the following rule for your decision: whenever you
  1498.           prefix some URLs with CGI-scripts to force them to be
  1499.           processed by the CGI-script, the chance is high that you
  1500.           will run into problems (or even overhead) on
  1501.           sub-requests. In these cases, use this flag.</p>
  1502.         </li>
  1503.  
  1504.         <li>'<strong><code>nocase|NC</code></strong>'
  1505.         (<strong>n</strong>o <strong>c</strong>ase)<br />
  1506.          This makes the <em>Pattern</em> case-insensitive,
  1507.         <em>i.e.</em>, there is no difference between 'A-Z' and
  1508.         'a-z' when <em>Pattern</em> is matched against the current
  1509.         URL.</li>
  1510.  
  1511.         <li>'<strong><code>qsappend|QSA</code></strong>'
  1512.         (<strong>q</strong>uery <strong>s</strong>tring
  1513.         <strong>a</strong>ppend)<br />
  1514.          This flag forces the rewriting engine to append a query
  1515.         string part in the substitution string to the existing one
  1516.         instead of replacing it. Use this when you want to add more
  1517.         data to the query string via a rewrite rule.</li>
  1518.  
  1519.         <li>
  1520.           '<strong><code>noescape|NE</code></strong>'
  1521.           (<strong>n</strong>o URI <strong>e</strong>scaping of
  1522.           output)<br />
  1523.            This flag keeps mod_rewrite from applying the usual URI
  1524.           escaping rules to the result of a rewrite. Ordinarily,
  1525.           special characters (such as '%', '$', ';', and so on)
  1526.           will be escaped into their hexcode equivalents ('%25',
  1527.           '%24', and '%3B', respectively); this flag prevents this
  1528.           from being done. This allows percent symbols to appear in
  1529.           the output, as in 
  1530. <example>
  1531.     RewriteRule /foo/(.*) /bar?arg=P1\%3d$1 [R,NE]
  1532. </example>
  1533.  
  1534.           which would turn '<code>/foo/zed</code>' into a safe
  1535.           request for '<code>/bar?arg=P1=zed</code>'. 
  1536.         </li>
  1537.  
  1538.         <li>
  1539.           '<strong><code>passthrough|PT</code></strong>'
  1540.           (<strong>p</strong>ass <strong>t</strong>hrough to next
  1541.           handler)<br />
  1542.            This flag forces the rewriting engine to set the
  1543.           <code>uri</code> field of the internal
  1544.           <code>request_rec</code> structure to the value of the
  1545.           <code>filename</code> field. This flag is just a hack to
  1546.           be able to post-process the output of
  1547.           <code>RewriteRule</code> directives by
  1548.           <code>Alias</code>, <code>ScriptAlias</code>,
  1549.           <code>Redirect</code>, <em>etc.</em> directives from
  1550.           other URI-to-filename translators. A trivial example to
  1551.           show the semantics: If you want to rewrite
  1552.           <code>/abc</code> to <code>/def</code> via the rewriting
  1553.           engine of <code>mod_rewrite</code> and then
  1554.           <code>/def</code> to <code>/ghi</code> with
  1555.           <code>mod_alias</code>: 
  1556. <example>
  1557.     RewriteRule ^/abc(.*)  /def$1 [PT]<br />
  1558.     Alias       /def       /ghi
  1559. </example>
  1560.           If you omit the <code>PT</code> flag then
  1561.           <code>mod_rewrite</code> will do its job fine,
  1562.           <em>i.e.</em>, it rewrites <code>uri=/abc/...</code> to
  1563.           <code>filename=/def/...</code> as a full API-compliant
  1564.           URI-to-filename translator should do. Then
  1565.           <code>mod_alias</code> comes and tries to do a
  1566.           URI-to-filename transition which will not work. 
  1567.  
  1568.           <p>Note: <strong>You have to use this flag if you want to
  1569.           intermix directives of different modules which contain
  1570.           URL-to-filename translators</strong>. The typical example
  1571.           is the use of <code>mod_alias</code> and
  1572.           <code>mod_rewrite</code>..</p>
  1573.         </li>
  1574.  
  1575.         <li>'<strong><code>skip|S</code></strong>=<em>num</em>'
  1576.         (<strong>s</strong>kip next rule(s))<br />
  1577.          This flag forces the rewriting engine to skip the next
  1578.         <em>num</em> rules in sequence when the current rule
  1579.         matches. Use this to make pseudo if-then-else constructs:
  1580.         The last rule of the then-clause becomes
  1581.         <code>skip=N</code> where N is the number of rules in the
  1582.         else-clause. (This is <strong>not</strong> the same as the
  1583.         'chain|C' flag!)</li>
  1584.  
  1585.         <li>
  1586.         '<strong><code>env|E=</code></strong><em>VAR</em>:<em>VAL</em>'
  1587.         (set <strong>e</strong>nvironment variable)<br />
  1588.          This forces an environment variable named <em>VAR</em> to
  1589.         be set to the value <em>VAL</em>, where <em>VAL</em> can
  1590.         contain regexp backreferences <code>$N</code> and
  1591.         <code>%N</code> which will be expanded. You can use this
  1592.         flag more than once to set more than one variable. The
  1593.         variables can be later dereferenced in many situations, but
  1594.         usually from within XSSI (via <code><!--#echo
  1595.         var="VAR"--></code>) or CGI (<em>e.g.</em>
  1596.         <code>$ENV{'VAR'}</code>). Additionally you can dereference
  1597.         it in a following RewriteCond pattern via
  1598.         <code>%{ENV:VAR}</code>. Use this to strip but remember
  1599.         information from URLs.</li>
  1600.  
  1601.         <li>
  1602.         '<strong><code>cookie|CO=</code></strong><em>NAME</em>:<em>VAL</em>:<em>domain</em>[:<em>lifetime</em>[:<em>path</em>]]'
  1603.         (set <strong>co</strong>cookie)<br />
  1604.         This sets a cookie on the client's browser.  The cookie's name
  1605.         is specified by <em>NAME</em> and the value is
  1606.         <em>VAL</em>. The <em>domain</em> field is the domain of the
  1607.         cookie, such as '.apache.org',the optional <em>lifetime</em>
  1608.     is the lifetime of the cookie in minutes, and the optional 
  1609.     <em>path</em> is the path of the cookie</li>
  1610.  
  1611.       </ul>
  1612.  
  1613. <note><title>Note</title> Never forget that <em>Pattern</em> is
  1614. applied to a complete URL in per-server configuration
  1615. files. <strong>But in per-directory configuration files, the
  1616. per-directory prefix (which always is the same for a specific
  1617. directory!) is automatically <em>removed</em> for the pattern matching
  1618. and automatically <em>added</em> after the substitution has been
  1619. done.</strong> This feature is essential for many sorts of rewriting,
  1620. because without this prefix stripping you have to match the parent
  1621. directory which is not always possible.
  1622.  
  1623.             <p>There is one exception: If a substitution string
  1624.             starts with ``<code>http://</code>'' then the directory
  1625.             prefix will <strong>not</strong> be added and an
  1626.             external redirect or proxy throughput (if flag
  1627.             <strong>P</strong> is used!) is forced!</p>
  1628. </note>
  1629.  
  1630. <note><title>Note</title>
  1631.  To enable the rewriting engine
  1632.           for per-directory configuration files you need to set
  1633.           ``<code>RewriteEngine On</code>'' in these files
  1634.           <strong>and</strong> ``<code>Options
  1635.           FollowSymLinks</code>'' must be enabled. If your
  1636.           administrator has disabled override of
  1637.           <code>FollowSymLinks</code> for a user's directory, then
  1638.           you cannot use the rewriting engine. This restriction is
  1639.           needed for security reasons.
  1640. </note>
  1641.  
  1642.       <p>Here are all possible substitution combinations and their
  1643.       meanings:</p>
  1644.  
  1645.       <p><strong>Inside per-server configuration
  1646.       (<code>httpd.conf</code>)<br />
  1647.        for request ``<code>GET
  1648.       /somepath/pathinfo</code>'':</strong><br />
  1649.       </p>
  1650.  
  1651. <note><pre>
  1652. <strong>Given Rule</strong>                                      <strong>Resulting Substitution</strong>
  1653. ----------------------------------------------  ----------------------------------
  1654. ^/somepath(.*) otherpath$1                      not supported, because invalid!
  1655.  
  1656. ^/somepath(.*) otherpath$1  [R]                 not supported, because invalid!
  1657.  
  1658. ^/somepath(.*) otherpath$1  [P]                 not supported, because invalid!
  1659. ----------------------------------------------  ----------------------------------
  1660. ^/somepath(.*) /otherpath$1                     /otherpath/pathinfo
  1661.  
  1662. ^/somepath(.*) /otherpath$1 [R]                 http://thishost/otherpath/pathinfo
  1663.                                                 via external redirection
  1664.  
  1665. ^/somepath(.*) /otherpath$1 [P]                 not supported, because silly!
  1666. ----------------------------------------------  ----------------------------------
  1667. ^/somepath(.*) http://thishost/otherpath$1      /otherpath/pathinfo
  1668.  
  1669. ^/somepath(.*) http://thishost/otherpath$1 [R]  http://thishost/otherpath/pathinfo
  1670.                                                 via external redirection
  1671.  
  1672. ^/somepath(.*) http://thishost/otherpath$1 [P]  not supported, because silly!
  1673. ----------------------------------------------  ----------------------------------
  1674. ^/somepath(.*) http://otherhost/otherpath$1     http://otherhost/otherpath/pathinfo
  1675.                                                 via external redirection
  1676.  
  1677. ^/somepath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfo
  1678.                                                 via external redirection
  1679.                                                 (the [R] flag is redundant)
  1680.  
  1681. ^/somepath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfo
  1682.                                                 via internal proxy
  1683. </pre></note>
  1684.  
  1685.       <p><strong>Inside per-directory configuration for
  1686.       <code>/somepath</code><br />
  1687.        (<em>i.e.</em>, file <code>.htaccess</code> in dir
  1688.       <code>/physical/path/to/somepath</code> containing
  1689.       <code>RewriteBase /somepath</code>)<br />
  1690.        for request ``<code>GET
  1691.       /somepath/localpath/pathinfo</code>'':</strong><br /> 
  1692.      </p>
  1693.  
  1694. <note><pre>
  1695. <strong>Given Rule</strong>                                      <strong>Resulting Substitution</strong>
  1696. ----------------------------------------------  ----------------------------------
  1697. ^localpath(.*) otherpath$1                      /somepath/otherpath/pathinfo
  1698.  
  1699. ^localpath(.*) otherpath$1  [R]                 http://thishost/somepath/otherpath/pathinfo
  1700.                                                 via external redirection
  1701.  
  1702. ^localpath(.*) otherpath$1  [P]                 not supported, because silly!
  1703. ----------------------------------------------  ----------------------------------
  1704. ^localpath(.*) /otherpath$1                     /otherpath/pathinfo
  1705.  
  1706. ^localpath(.*) /otherpath$1 [R]                 http://thishost/otherpath/pathinfo
  1707.                                                 via external redirection
  1708.  
  1709. ^localpath(.*) /otherpath$1 [P]                 not supported, because silly!
  1710. ----------------------------------------------  ----------------------------------
  1711. ^localpath(.*) http://thishost/otherpath$1      /otherpath/pathinfo
  1712.  
  1713. ^localpath(.*) http://thishost/otherpath$1 [R]  http://thishost/otherpath/pathinfo
  1714.                                                 via external redirection
  1715.  
  1716. ^localpath(.*) http://thishost/otherpath$1 [P]  not supported, because silly!
  1717. ----------------------------------------------  ----------------------------------
  1718. ^localpath(.*) http://otherhost/otherpath$1     http://otherhost/otherpath/pathinfo
  1719.                                                 via external redirection
  1720.  
  1721. ^localpath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfo
  1722.                                                 via external redirection
  1723.                                                 (the [R] flag is redundant)
  1724.  
  1725. ^localpath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfo
  1726.                                                 via internal proxy
  1727. </pre></note>
  1728.  
  1729.       <p><strong>Example:</strong></p>
  1730.  
  1731.       <p>We want to rewrite URLs of the form </p>
  1732.  
  1733.         <p class="indent">
  1734.           <code>/</code> <em>Language</em> <code>/~</code>
  1735.           <em>Realname</em> <code>/.../</code> <em>File</em>
  1736.         </p>
  1737.  
  1738.         <p>into </p>
  1739.  
  1740.         <p class="indent">
  1741.           <code>/u/</code> <em>Username</em> <code>/.../</code>
  1742.           <em>File</em> <code>.</code> <em>Language</em>
  1743.         </p>
  1744.  
  1745.         <p>We take the rewrite mapfile from above and save it under
  1746.         <code>/path/to/file/map.txt</code>. Then we only have to
  1747.         add the following lines to the Apache server configuration
  1748.         file:</p>
  1749.  
  1750. <example>
  1751. <pre>
  1752. RewriteLog   /path/to/file/rewrite.log
  1753. RewriteMap   real-to-user               txt:/path/to/file/map.txt
  1754. RewriteRule  ^/([^/]+)/~([^/]+)/(.*)$   /u/${real-to-user:$2|nobody}/$3.$1
  1755. </pre>
  1756.    </example>
  1757.   </usage>
  1758.  </directivesynopsis>
  1759. </modulesynopsis>
  1760.