890 lines
52 KiB
HTML
890 lines
52 KiB
HTML
<?xml version="1.0" encoding="UTF-8"?>
|
||
<!DOCTYPE html
|
||
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
<html lang="en-us" xml:lang="en-us">
|
||
<head>
|
||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||
<meta name="security" content="public" />
|
||
<meta name="Robots" content="index,follow" />
|
||
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
|
||
<meta name="DC.Type" content="topic" />
|
||
<meta name="DC.Title" content="Module mod_rewrite" />
|
||
<meta name="copyright" content="(C) Copyright IBM Corporation 2002,2006" />
|
||
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2002,2006" />
|
||
<meta name="DC.Format" content="XHTML" />
|
||
<meta name="DC.Identifier" content="rzaiemod_rewrite" />
|
||
<meta name="DC.Language" content="en-us" />
|
||
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
||
<!-- US Government Users Restricted Rights -->
|
||
<!-- Use, duplication or disclosure restricted by -->
|
||
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
||
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
|
||
<link rel="stylesheet" type="text/css" href="./ic.css" />
|
||
<title>Module mod_rewrite</title>
|
||
</head>
|
||
<body id="rzaiemod_rewrite"><a name="rzaiemod_rewrite"><!-- --></a>
|
||
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
||
<!--Java sync-link--><h1 class="topictitle1">Module mod_rewrite</h1>
|
||
<div><div class="important"><span class="importanttitle">Important:</span> Information
|
||
for this topic supports the latest PTF levels for HTTP Server for i5/OS .
|
||
It is recommended that you install the latest PTFs to upgrade to the latest
|
||
level of the HTTP Server for i5/OS. Some of the topics documented here are
|
||
not available prior to this update. See <a href="http://www-03.ibm.com/servers/eserver/iseries/software/http/services/service.html" target="_blank">http://www.ibm.com/servers/eserver/iseries/software/http/services/service.htm</a> <img src="www.gif" alt="Link outside Information Center" /> for more information. </div>
|
||
<p><strong>Summary</strong></p>
|
||
<p>This module allows you to control URL access to your HTTP Server. </p>
|
||
<p>For example, to prevent a particular user agent called Web crawler
|
||
from accessing any pages on the server. To do this, include the following
|
||
directives in your configuration: </p>
|
||
<blockquote><pre>RewriteEngine on
|
||
RewriteCond %{HTTP_USER_AGENT} ^Webcrawler
|
||
RewriteRule ^.*$ - [F,L]</pre>
|
||
</blockquote>
|
||
<p>The first line enables the rewrite engine. The second line provides a test
|
||
that returns true if the HTTP_USER_AGENT string starts with the letters Web
|
||
crawler. If the second line is true, then the third line takes any URL string
|
||
and returns a forbidden message to the client. </p>
|
||
<p><strong>Directives</strong></p>
|
||
<ul><li><a href="#rewritebase">RewriteBase</a></li>
|
||
<li><a href="#rewritecond">RewriteCond</a></li>
|
||
<li><a href="#rewriteengine">RewriteEngine</a></li>
|
||
<li><a href="#rewritelog">RewriteLog</a></li>
|
||
<li><a href="#rewriteloglevel">RewriteLogLevel</a></li>
|
||
<li><a href="#rewritemap">RewriteMap</a></li>
|
||
<li><a href="#rewriteoptions">RewriteOptions</a></li>
|
||
<li><a href="#rewriterule">RewriteRule</a> </li>
|
||
</ul>
|
||
</div>
|
||
<div class="hr" id="rewritebase"><a name="rewritebase"><!-- --></a><h2 class="topictitle2">RewriteBase</h2>
|
||
<div>
|
||
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" frame="void" border="0" rules="none"><tbody><tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Module">Module</a></strong>: mod_rewrite </td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Syntax">Syntax</a></strong>: RewriteBase <em>Base_URL</em></td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Default">Default</a></strong>: RewriteBase physical directory path</td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Context">Context</a></strong>: <span id="rewritebase__rewritebase_context"><a name="rewritebase__rewritebase_context"><!-- --></a>Directory,
|
||
but not Location, .htaccess </span></td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Override">Override</a></strong>: FileInfo </td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Origin">Origin</a></strong>: <span id="rewritebase__rewritebase_origin"><a name="rewritebase__rewritebase_origin"><!-- --></a>Apache </span></td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Example">Example</a></strong>: RewriteBase /xyz</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<p>The RewriteBase directive explicitly sets the base URL for per-directory
|
||
rewrites. As you will see below, RewriteRule can be used in per-directory
|
||
config files (.htaccess). There it will act locally (for example, the local
|
||
directory prefix is stripped at this stage of processing and your rewriting
|
||
rules act only on the remainder). At the end it is automatically added back
|
||
to the path.</p>
|
||
<p>When a substitution occurs for a new URL, this module has to re-inject
|
||
the URL into the processing server. To be able to do this it needs to know
|
||
what the corresponding URL-prefix or URL-base is. By default this prefix is
|
||
the corresponding filepath itself. At most, Web sites URLs are not directly
|
||
related to physical filename paths, so this assumption is usually incorrect.
|
||
In this case, you have to use the RewriteBase directive to specify the correct
|
||
URL-prefix. </p>
|
||
<div class="note"><span class="notetitle">Note:</span> If your webserver's URLs are not directly related to physical file paths,
|
||
you have to use RewriteBase in every .htaccess file where you want to use
|
||
RewriteRule directives.</div>
|
||
<p>Assume the following per-directory configuration file (/abc/def is the
|
||
physical path of /xyz, and the server has the 'Alias /xyz /ABC/def' established). </p>
|
||
<pre class="block">RewriteEngine On
|
||
RewriteBase /xyz
|
||
RewriteRule ^old\.html$ new.html</pre>
|
||
<p>In the above example, a request to /xyz/old.html is correctly rewritten
|
||
to the physical file /ABC/def/new.html. </p>
|
||
</div>
|
||
</div>
|
||
<div class="hr" id="rewritecond"><a name="rewritecond"><!-- --></a><h2 class="topictitle2">RewriteCond</h2>
|
||
<div>
|
||
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" frame="void" border="0" rules="none"><tbody><tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Module">Module</a></strong>: mod_rewrite </td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Syntax">Syntax</a></strong>: RewriteCond <em>TestString CondPattern [flags]</em></td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Default">Default</a></strong>: none</td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Context">Context</a></strong>: <span id="rewritecond__rewritecond_context"><a name="rewritecond__rewritecond_context"><!-- --></a>server config,
|
||
virtual host, directory, .htaccess </span></td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Override">Override</a></strong>: FileInfo </td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Origin">Origin</a></strong>: <span id="rewritecond__rewritecond_origin"><a name="rewritecond__rewritecond_origin"><!-- --></a>Apache </span></td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Example">Example</a></strong>: RewriteCond %{HTTP_USER_AGENT} ^Mozilla.*</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<p>The RewriteCond directive defines a rule condition. Precede a RewriteRule
|
||
directive with one or more RewriteCond directives. The following rewriting
|
||
rule is only used if its pattern matches the current state of the URI and
|
||
if these additional conditions apply.</p>
|
||
<dl class="block"><dt class="dlterm"><strong>Parameter One</strong>: <em>TestString</em></dt>
|
||
<dd><ul><li>The <em>TestString</em> parameter can contain the following expanded constructs
|
||
in addition to plain text:<ul><li><strong>RewriteRule backreferences</strong>: These are backreferences of the form.<dl><dt class="dlterm">$N</dt>
|
||
<dd>(0 <= N <= 9) that provide access to the grouped sections (those
|
||
in parenthesis) of the pattern from the corresponding RewriteRule directive
|
||
(the one following the current RewriteCond directives).</dd>
|
||
</dl>
|
||
</li>
|
||
<li><strong>RewriteCond backreferences</strong>: These are backreferences of the form.<dl><dt class="dlterm">%N</dt>
|
||
<dd>0 <= N <= 9) that provide access to the grouped sections (those
|
||
in parenthesis) of the pattern from the last matched RewriteCond directive
|
||
in the current conditions</dd>
|
||
</dl>
|
||
</li>
|
||
<li><strong>RewriteMap expansions</strong>: These are expansions of the form.<dl><dt class="dlterm">${mapname:key|default} </dt>
|
||
<dd>See <a href="#rewritemap">RewriteMap</a> for more details.</dd>
|
||
</dl>
|
||
</li>
|
||
<li><strong>Server-Variables</strong>: These are variables of the form<dl><dt class="dlterm">%{ NAME_OF_VARIABLE } </dt>
|
||
<dd>Where NAME_OF_VARIABLE can be a string taken from the following list:<dl><dt class="dlterm">HTTP headers</dt>
|
||
<dd><ul><li>HTTP_USER_AGENT </li>
|
||
<li>HTTP_REFERRER </li>
|
||
<li>HTTP_COOKIE</li>
|
||
<li>HTTP_FORWARDED</li>
|
||
<li>HTTP_HOST</li>
|
||
<li>HTTP_PROXY_CONNECTION</li>
|
||
<li>HTTP_ACCEPT</li>
|
||
</ul>
|
||
</dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">Connection and Request</dt>
|
||
<dd><ul><li>REMOTE_ADDR </li>
|
||
<li>REMOTE_HOST </li>
|
||
<li>REMOTE_USER</li>
|
||
<li>REMOTE_IDENT </li>
|
||
<li>REQUEST_METHOD </li>
|
||
<li>SCRIPT_FILENAME </li>
|
||
<li>PATH_INFO </li>
|
||
<li>QUERY_STRING </li>
|
||
<li>AUTH_TYPE </li>
|
||
</ul>
|
||
</dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">Server Internals</dt>
|
||
<dd><ul><li>DOCUMENT_ROOT</li>
|
||
<li>SERVER_ADMIN</li>
|
||
<li>SERVER_NAME</li>
|
||
<li>SERVER_ADDR</li>
|
||
<li>SERVER_PORT</li>
|
||
<li>SERVER_PROTOCOL</li>
|
||
<li>SERVER_SOFTWARE </li>
|
||
</ul>
|
||
</dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">System</dt>
|
||
<dd><ul><li>TIME_YEAR</li>
|
||
<li>TIME_MON</li>
|
||
<li>TIME_DAY</li>
|
||
<li>TIME_HOUR</li>
|
||
<li>TIME_MIN</li>
|
||
<li>TIME_SEC</li>
|
||
<li>TIME_WDAY</li>
|
||
<li>TIME</li>
|
||
</ul>
|
||
</dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">Special</dt>
|
||
<dd><ul><li>API_VERSION</li>
|
||
<li>THE_REQUEST</li>
|
||
<li>REQUEST_URI</li>
|
||
<li>REQUEST_FILENAME</li>
|
||
<li>IS_SUBREQ</li>
|
||
</ul>
|
||
</dd>
|
||
</dl>
|
||
<div class="tip"><span class="tiptitle">Tip:</span> <ol><li>The variables SCRIPT_FILENAME and REQUEST_FILENAME contain the same value
|
||
(the value of the filename field of the internal request_rec structure of
|
||
the server). The first name is just the commonly known CGI variable name while
|
||
the second is the consistent counterpart to REQUEST_URI (which contains the
|
||
value of the URI field of request_rec). </li>
|
||
<li>There is the special format: %{ENV:variable} where variable can be any
|
||
environment variable. This is looked-up via internal structures and (if not
|
||
found there) via getenv() from the server process. </li>
|
||
<li>There is the special format: %{HTTP:header} where header can be any HTTP
|
||
MIME-header name. This is looked-up from the HTTP request. Example: %{HTTP:Proxy-Connection}
|
||
is the value of the HTTP header ``Proxy-Connection:''. </li>
|
||
<li>There is the special format %{LA-U:variable} for look-aheads that perform
|
||
an internal (URL-based) sub-request to determine the final value of variable.
|
||
Use this when you want to use a variable for rewriting (which is actually
|
||
set later in an API phase and thus is not available at the current stage).
|
||
For instance when you want to rewrite according to the REMOTE_USER variable
|
||
from within the per-server context (httpd.conf file) you have to use %{LA-U:REMOTE_USER}
|
||
because this variable is set by the authorization phases that come after the
|
||
URL translation phase where mod_rewrite operates. On the other hand, because
|
||
mod_rewrite implements its per-directory context (.htaccess file) via the
|
||
Fixup phase of the API and because the authorization phases come before this
|
||
phase, you just can use %{REMOTE_USER} there. </li>
|
||
<li>There is the special format: %{LA-F:variable} that performs an internal
|
||
(filename-based) sub-request to determine the final value of variable. Most
|
||
of the time this is the same as LA-U above. </li>
|
||
</ol>
|
||
</div>
|
||
</dd>
|
||
</dl>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
</dd>
|
||
</dl>
|
||
<dl class="block"><dt class="dlterm"><strong>Parameter Two</strong>: <em>CondPattern</em></dt>
|
||
<dd><ul><li>The <em>CondPattern</em> parameter is the condition pattern (a regular expression)
|
||
that is applied to the current instance of the TestString. TestString is evaluated
|
||
and then matched against CondPattern. <p>CondPattern is a standard Extended
|
||
Regular Expression with some additions: </p>
|
||
<ol><li>You can prefix the pattern string with a '!' character (exclamation mark)
|
||
to specify a non-matching pattern. </li>
|
||
<li>There are some special CondPattern variants. Instead of real regular expression
|
||
strings you can also use one of the following: <dl><dt class="dlterm"><CondPattern</dt>
|
||
<dd>Treats the CondPattern as a plain string and compares it lexically to
|
||
TestString. True if TestString is lexically lower than CondPattern.</dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">>CondPattern</dt>
|
||
<dd>Treats the CondPattern as a plain string and compares it lexically to
|
||
TestString. True if TestString is lexically greater than CondPattern. </dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">=CondPattern</dt>
|
||
<dd>Treats the CondPattern as a plain string and compares it lexically to
|
||
TestString. True if TestString is lexically equal to CondPattern (the two
|
||
strings are exactly equal, character by character). If CondPattern is just
|
||
"" (two quotation marks) this compares TestString to the empty string. </dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">-d</dt>
|
||
<dd>Treats the TestString as a pathname and tests if it exists and is a directory. </dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">-f</dt>
|
||
<dd>Treats the TestString as a pathname and tests if it exists and is a regular
|
||
file. </dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">-s</dt>
|
||
<dd>Treats the TestString as a pathname and tests if it exists and is a regular
|
||
file with size greater than zero. </dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">-l</dt>
|
||
<dd>Treats the TestString as a pathname and tests if it exists and is a symbolic
|
||
link. </dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">-F</dt>
|
||
<dd>Checks if TestString is a valid file and accessible via all the server's
|
||
currently-configured access controls for that path. This uses an internal
|
||
subrequest to determine the check. </dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">-U</dt>
|
||
<dd>Checks if TestString is a valid URL and accessible via all the server's
|
||
currently-configured access controls for that path. This uses an internal
|
||
subrequest to determine the check. </dd>
|
||
</dl>
|
||
<div class="note"><span class="notetitle">Note:</span> All of these tests can also be prefixed by an exclamation
|
||
mark ('!') to negate their meaning.</div>
|
||
</li>
|
||
</ol>
|
||
</li>
|
||
</ul>
|
||
</dd>
|
||
</dl>
|
||
<dl class="block"><dt class="dlterm"><strong>Parameter Three</strong>: <em>flags</em></dt>
|
||
<dd><ul><li>The <em>flags</em> parameter is appended to the CondPattern parameter. The <em>flags</em> parameter
|
||
is a comma -serapertaed list of the following flags:<dl><dt class="dlterm">nocase|NC</dt>
|
||
<dd>This makes the test case-insensitive (there is no difference between 'A-Z'
|
||
and AZ both in the expanded TestString and the CondPattern). This flag is
|
||
effective only for comparisons between TestString and CondPattern. It has
|
||
no effect on filesystem and subrequest checks. </dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">ornext|OR</dt>
|
||
<dd>Use this to combine rule conditions with a local OR instead of the implicit
|
||
AND. Typical example: <pre class="block">RewriteCond %{REMOTE_HOST} ^host1.* [OR]
|
||
RewriteCond %{REMOTE_HOST} ^host2.* [OR]
|
||
RewriteCond %{REMOTE_HOST} ^host3.*
|
||
RewriteRule ...some special stuff for any of these hosts...</pre>
|
||
Without
|
||
this flag you would have to write the cond/rule three times. </dd>
|
||
</dl>
|
||
</li>
|
||
</ul>
|
||
</dd>
|
||
</dl>
|
||
<p>To rewrite the Homepage of a site according to the ``User-Agent:'' header
|
||
of the request, you can use the following: </p>
|
||
<pre class="block">RewriteCond %{HTTP_USER_AGENT} ^Mozilla.*
|
||
RewriteRule ^/$ /homepage.max.html [L]
|
||
|
||
RewriteCond %{HTTP_USER_AGENT} ^Lynx.*
|
||
RewriteRule ^/$ /homepage.min.html [L]
|
||
|
||
RewriteRule ^/$ /homepage.std.html [L]</pre>
|
||
<p>If you use Netscape Navigator as your browser (which identifies itself
|
||
as 'Mozilla'), then you get the max homepage, which includes Frames and so
|
||
on. If you use the Lynx browser (which is Terminal-based), then you get the
|
||
min homepage, which contains no images, no tables, and so on. If you use any
|
||
other browser you get the standard homepage. </p>
|
||
</div>
|
||
</div>
|
||
<div class="hr" id="rewriteengine"><a name="rewriteengine"><!-- --></a><h2 class="topictitle2">RewriteEngine</h2>
|
||
<div>
|
||
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" frame="void" border="0" rules="none"><tbody><tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Module">Module</a></strong>: mod_rewrite </td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Syntax">Syntax</a></strong>: RewriteEngine <em>on | off </em></td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Default">Default</a></strong>: RewriteEngine off </td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Context">Context</a></strong>: <span id="rewriteengine__rewriteengine_context"><a name="rewriteengine__rewriteengine_context"><!-- --></a>server config,
|
||
virtual host, directory, .htaccess </span></td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Override">Override</a></strong>: FileInfo </td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Origin">Origin</a></strong>: <span id="rewriteengine__rewriteengine_origin"><a name="rewriteengine__rewriteengine_origin"><!-- --></a>Apache </span></td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Example">Example</a></strong>: RewriteEngine on </td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<p>The RewriteEngine directive enables or disables the runtime rewriting engine.
|
||
You can use this directive to disable the module instead of commenting out
|
||
all the RewriteRule directives. </p>
|
||
<dl class="block"><dt class="dlterm"><strong>Parameter</strong>: <em>on | off</em></dt>
|
||
<dd><ul><li>If set to <em>on</em> runtime processing is enabled. If it is set to <em>off</em> runtime
|
||
processing is disabled and this module does not runtime processing at all.</li>
|
||
</ul>
|
||
</dd>
|
||
</dl>
|
||
<div class="note"><span class="notetitle">Note:</span> By default, rewrite configurations are not inherited. This means that
|
||
you need to have the RewriteEngine on for each virtual host in which you want
|
||
to use it. </div>
|
||
</div>
|
||
</div>
|
||
<div class="hr" id="rewritelog"><a name="rewritelog"><!-- --></a><h2 class="topictitle2">RewriteLog</h2>
|
||
<div>
|
||
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" frame="void" border="0" rules="none"><tbody><tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Module">Module</a></strong>: mod_rewrite</td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Syntax">Syntax</a></strong>: RewriteLog <em>filename</em></td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Default">Default</a></strong>: none</td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Context">Context</a></strong>: <span id="rewritelog__rewritelog_context"><a name="rewritelog__rewritelog_context"><!-- --></a>server config,
|
||
virtual host</span></td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Override">Override</a></strong>: none</td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Origin">Origin</a></strong>: <span id="rewritelog__rewritelog_origin"><a name="rewritelog__rewritelog_origin"><!-- --></a>Apache</span></td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Example">Example</a></strong>: RewriteLog "/usr/local/var/apache/logs/rewrite.log"</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<p>The RewriteLog directive sets the name of the file to which the server
|
||
logs any rewriting actions it performs. The directive should occur only once
|
||
per server configuration. </p>
|
||
<dl class="block"><dt class="dlterm"><strong>Parameter One</strong>: <em>filename</em></dt>
|
||
<dd><ul><li>The <em>filename</em> parameter is any valid filename that QTMHHTTP has
|
||
authority to write to. If the name does not begin with a slash ('/') then
|
||
it is assumed to be relative to the Server Root. For example,<pre class="block">RewriteLog "/usr/local/var/apache/logs/rewrite.log"</pre>
|
||
</li>
|
||
</ul>
|
||
</dd>
|
||
</dl>
|
||
<div class="note"><span class="notetitle">Note:</span> To disable the logging of rewriting actions it is not recommended to
|
||
set Filename to /dev/null, because although the rewriting engine does not
|
||
then output to a logfile, it still creates the logfile output internally.
|
||
This will slow down the server with no advantage to the administrator. To
|
||
disable logging either remove or comment out the RewriteLog directive or use <tt>RewriteLogLevel
|
||
0!</tt> in your configuration.</div>
|
||
</div>
|
||
</div>
|
||
<div class="hr" id="rewriteloglevel"><a name="rewriteloglevel"><!-- --></a><h2 class="topictitle2">RewriteLogLevel</h2>
|
||
<div>
|
||
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" frame="void" border="0" rules="none"><tbody><tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Module">Module</a></strong>: mod_rewrite</td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Syntax">Syntax</a></strong>: RewriteLogLevel <em>Level</em></td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Default">Default</a></strong>: RewriteLogLevel 0</td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Context">Context</a></strong>: <span id="rewriteloglevel__rewriteloglevel_context"><a name="rewriteloglevel__rewriteloglevel_context"><!-- --></a>server
|
||
config, virtual host</span></td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Override">Override</a></strong>: none</td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Origin">Origin</a></strong>: <span id="rewriteloglevel__rewriteloglevel_origin"><a name="rewriteloglevel__rewriteloglevel_origin"><!-- --></a>Apache</span></td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Example">Example</a></strong>: RewriteLogLevel 3</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<p>The RewriteLogLevel directive sets the level of the rewriting logfile.</p>
|
||
<dl class="block"><dt class="dlterm"><strong>Parameter</strong>: <em>Level</em></dt>
|
||
<dd><ul><li>The Level parameter sets the level of the rewriting logfile. The default
|
||
level 0 means no logging, while 9 means that practically all actions are logged.
|
||
For example, <pre class="block">RewriteLogLevel 3</pre>
|
||
To
|
||
disable the logging of rewriting actions simply set Level to 0. This disables
|
||
all rewrite action logs.</li>
|
||
</ul>
|
||
</dd>
|
||
</dl>
|
||
<div class="note"><span class="notetitle">Note:</span> Using a high value for Level will slow down your server dramatically.
|
||
Use the rewriting logfile at a Level greater than 2 only for debugging purposes. </div>
|
||
</div>
|
||
</div>
|
||
<div class="hr" id="rewritemap"><a name="rewritemap"><!-- --></a><h2 class="topictitle2">RewriteMap</h2>
|
||
<div>
|
||
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" frame="void" border="0" rules="none"><tbody><tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Module">Module</a></strong>: mod_rewrite</td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Syntax">Syntax</a></strong>: RewriteMap <em>MapName MapType:MapSource</em></td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Default">Default</a></strong>: none</td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Context">Context</a></strong>: <span id="rewritemap__rewritemap_context"><a name="rewritemap__rewritemap_context"><!-- --></a>server config,
|
||
virtual host</span></td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Override">Override</a></strong>: none</td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Origin">Origin</a></strong>: <span id="rewritemap__rewritemap_origin"><a name="rewritemap__rewritemap_origin"><!-- --></a>Apache</span></td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Example">Example</a></strong>: RewriteMap servers rnd:/path/to/file/map.txt</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<p>The RewriteMap directive defines a Rewriting Map that can be used inside
|
||
rule substitution strings by the mapping-functions to insert or substitute
|
||
fields through a key lookup. The source of this lookup can be of various types.
|
||
</p>
|
||
<dl class="block"><dt class="dlterm"><strong>Parameter</strong>: <em>MapName</em></dt>
|
||
<dd><ul><li>The <em>MapName</em> parameter is the name of the map and is used to specify
|
||
a mapping-function for the substitution strings of a rewriting rule via one
|
||
of the following constructs: <pre class="block">${ MapName : LookupKey }
|
||
${ MapName : LookupKey | DefaultValue }</pre>
|
||
<p>When such a construct
|
||
occurs the map MapName is consulted and the key LookupKey is looked-up. If
|
||
the key is found, the map-function construct is substituted by SubstValue.
|
||
If the key is not found then it is substituted by DefaultValue or by the empty
|
||
string if no DefaultValue was specified. The following combinations for MapType
|
||
and MapSource can be used: </p>
|
||
<dl><dt class="dlterm">Standard Plain Text</dt>
|
||
<dd>MapType: txt, MapSource: Path to a file <p>This is the standard rewriting
|
||
map feature where the MapSource is a plain text file containing either blank
|
||
lines, comment lines (starting with a '#' character) or pairs like the following
|
||
(one per line): MatchingKey SubstituionValue.</p>
|
||
<p><strong>File example:</strong></p>
|
||
<pre class="block">##
|
||
## map.txt -- rewriting map
|
||
##
|
||
Ralf.B.Jones rbj # Operator
|
||
Mr.Joe.Average joe # Mr. Average</pre>
|
||
<p><strong>Directive example:</strong></p>
|
||
<pre class="block">RewriteMap real-to-user txt:/path/to/file/map.txt</pre>
|
||
</dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">Randomized Plain Text</dt>
|
||
<dd>MapType: rnd, MapSource: Path to a file <p>This is identical to the Standard
|
||
Plain Text variant above but with a special post-processing feature. After
|
||
looking up a value it is parsed according to the contained horizontal bar
|
||
( | ) characters which mean "or". In other words, the horizontal bars indicate
|
||
a set of alternatives from which the actual returned value is randomly chosen.
|
||
This feature was designed for load balancing in a reverse proxy situation
|
||
where the looked up values are server names.</p>
|
||
<p><strong>File example:</strong></p>
|
||
<pre class="block">##
|
||
## map.txt -- rewriting map
|
||
##
|
||
static www1|www2|www3|www4
|
||
dynamic www5|www6</pre>
|
||
<p><strong>Directive example:</strong></p>
|
||
<pre class="block">RewriteMap servers rnd:/path/to/file/map.txt</pre>
|
||
</dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">Internal Function</dt>
|
||
<dd>MapType: int, MapSource: Internal Apache function<p>The following internal
|
||
functions are valid:</p>
|
||
<dl><dt class="dlterm">toupper</dt>
|
||
<dd>Converts the looked up key to all upper case. </dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">tolower</dt>
|
||
<dd>Converts the looked up key to all lower case. </dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">escape</dt>
|
||
<dd>Translates special characters in the looked up key to hex-encodings. </dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">unescape</dt>
|
||
<dd>Translates hex-encodings in the looked up key back to special characters.</dd>
|
||
</dl>
|
||
</dd>
|
||
</dl>
|
||
</li>
|
||
</ul>
|
||
</dd>
|
||
</dl>
|
||
<p>The RewriteMap directive can occur more than once. For each mapping function
|
||
use one RewriteMap directive to declare its rewriting mapfile. While you cannot
|
||
declare a map in a per-directory context, it is possible to use this map in
|
||
a per-directory context. </p>
|
||
<div class="note"><span class="notetitle">Note:</span> The prg and dbm MapTypes are not supported.</div>
|
||
</div>
|
||
</div>
|
||
<div class="hr" id="rewriteoptions"><a name="rewriteoptions"><!-- --></a><h2 class="topictitle2">RewriteOptions</h2>
|
||
<div>
|
||
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" frame="void" border="0" rules="none"><tbody><tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Module">Module</a></strong>: mod_rewrite</td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Syntax">Syntax</a></strong>: RewriteOptions <em>Option</em></td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Default">Default</a></strong>: none</td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Context">Context</a></strong>: <span id="rewriteoptions__rewriteoptions_context"><a name="rewriteoptions__rewriteoptions_context"><!-- --></a>server
|
||
config, virtual host, directory, .htaccess</span></td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Override">Override</a></strong>: FileInfo</td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Origin">Origin</a></strong>: <span id="rewriteoptions__rewriteoptions_origin"><a name="rewriteoptions__rewriteoptions_origin"><!-- --></a>Apache</span></td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Example">Example</a></strong>: RewriteOptions inherit</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<p>The RewriteOptions directive sets some special options for the current
|
||
per-server or per-directory configuration.</p>
|
||
<blockquote><dl><dt class="dlterm"><strong>Parameter</strong>: <em>Option</em></dt>
|
||
<dd><ul><li>The <em>Option</em> parameter strings can be one of the following:<dl class="dlexpand"><dt class="dltermexpand"><strong>inherit</strong></dt>
|
||
<dd>This forces the current configuration to inherit the configuration of
|
||
the parent. In per-virtual-server context this means that the maps, conditions
|
||
and rules of the main server are inherited. In per-directory context this
|
||
means that conditions and rules of the parent directory's .htaccess configuration
|
||
are inherited.</dd>
|
||
</dl>
|
||
<dl class="dlexpand"><dt class="dltermexpand"><strong>MaxRedirects=<em>number</em></strong></dt>
|
||
<dd>This forces a request to terminate after reaching a maximum number of
|
||
redirects and responds with a 500 Internal Server Error. The <em>number</em> parameter
|
||
value is the maximum number of redirects allowed. This prevents endless loops
|
||
of internal redirects issued by per-directory RewriteRules. If additional
|
||
internal redirects are required, increase the default to the desired value.
|
||
For example, <samp class="codeph">RewriteOptions MaxRedirects=13</samp>.</dd>
|
||
</dl>
|
||
</li>
|
||
</ul>
|
||
</dd>
|
||
</dl>
|
||
</blockquote>
|
||
</div>
|
||
</div>
|
||
<div class="hr" id="rewriterule"><a name="rewriterule"><!-- --></a><h2 class="topictitle2">RewriteRule</h2>
|
||
<div>
|
||
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" frame="void" border="0" rules="none"><tbody><tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Module">Module</a></strong>: mod_rewrite </td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Syntax">Syntax</a></strong>: RewriteRule <em>pattern substitution [flags] </em></td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Default">Default</a></strong>: none </td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Context">Context</a></strong>: <span id="rewriterule__rewriterule_context"><a name="rewriterule__rewriterule_context"><!-- --></a>server config,
|
||
virtual host, directory, .htaccess </span></td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Override">Override</a></strong>: FileInfo </td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Origin">Origin</a></strong>: <span id="rewriterule__rewriterule_origin"><a name="rewriterule__rewriterule_origin"><!-- --></a>Apache </span></td>
|
||
</tr>
|
||
<tr><td colspan="2" valign="top"><strong><a href="rzaiedirective-dict.htm#rzaiedirective-dict__Example">Example</a></strong>: RewriteRule ^/ABC(.*) /def$1 [PT] </td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<p>The RewriteRule directive is the real rewriting workhorse. The directive
|
||
can occur more than once. Each directive then defines one single rewriting
|
||
rule. The definition order of these rules is important, because this order
|
||
is used when applying the rules at run-time. </p>
|
||
<dl class="block"><dt class="dlterm"><strong>Parameter One</strong>: <em>pattern </em></dt>
|
||
<dd><ul><li>The <em>pattern</em> parameter can be an extended regular expression which
|
||
gets applied to the current URL. Here ``current'' means the value of the URL
|
||
when this rule gets applied. This may not be the originally requested URL,
|
||
because any number of rules may already have matched and made alterations
|
||
to it. See <a href="rzaieenvvar.htm">Environment variables on HTTP Server</a> for more information. </li>
|
||
<li>Additionally in mod_rewrite the not character ('!') is a possible pattern
|
||
prefix. This gives you the ability to negate a pattern; to say, for instance:
|
||
``if the current URL does not match this pattern''. This can be used for exceptional
|
||
cases, where it is easier to match the negative pattern, or as a last default
|
||
rule. </li>
|
||
</ul>
|
||
</dd>
|
||
</dl>
|
||
<div class="note"><span class="notetitle">Note:</span> When using the not character to negate a pattern you cannot
|
||
have grouped wild card parts in the pattern. This is impossible because when
|
||
the pattern does not match, there are no contents for the groups, and you
|
||
cannot use $N in the substitution string. </div>
|
||
<dl class="block"><dt class="dlterm"><strong>Parameter Two</strong>: <em>substitution </em></dt>
|
||
<dd><ul><li>The <em>substitution</em> parameter is the string which is substituted for
|
||
(or replaces) the original URL for which Pattern matched. Beside plain text
|
||
you can use back-references $N to the RewriteRule pattern, back-references
|
||
%N to the last matched RewriteCond pattern, server-variables as in rule condition
|
||
test-strings (%{VARNAME}) and mapping-function calls (${mapname:key|default}). </li>
|
||
<li>Back-references are $N (N=0..9) identifiers which will be replaced by
|
||
the contents of the Nth group of the matched Pattern. The server-variables
|
||
are the same as for the TestString of a RewriteCond directive. The mapping-functions
|
||
come from the RewriteMap directive and are explained there. These three types
|
||
of variables are expanded in the order of the above list. As already mentioned
|
||
above, all the rewriting rules are applied to the Substitution (in the order
|
||
of definition in the config file). The URL is completely replaced by the Substitution
|
||
and the rewriting process goes on until there are no more rules unless explicitly
|
||
terminated by a L flag - see below. </li>
|
||
<li>There is a special substitution string named '-' which means: NO substitution.
|
||
It is useful to provide rewriting rules which only match some URLs but do
|
||
no substitution, for example, in conjunction with the C (chain) flag to be
|
||
able to have more than one pattern to be applied before a substitution occurs. </li>
|
||
</ul>
|
||
</dd>
|
||
</dl>
|
||
<div class="note"><span class="notetitle">Note:</span> You can even create URLs in the substitution string containing a query
|
||
string part. Just use a question mark inside the substitution string to indicate
|
||
that the following stuff should be re-injected into the QUERY_STRING. When
|
||
you want to erase an existing query string, end the substitution string with
|
||
just the question mark. There is a special feature: When you prefix a substitution
|
||
field with http://thishost[:thisport] then mod_rewrite automatically strips
|
||
it out. This auto reduction on implicit external redirect URLs is a useful
|
||
and important feature when used in combination with a mapping-function which
|
||
generates the hostname part. Have a look at the first example in the example
|
||
section below to understand this.</div>
|
||
<p>Remember, an unconditional external redirect to your own server will not
|
||
work with the prefix http://thishost because of this feature. To achieve such
|
||
a self-redirect, you have to use the R-flag (see below). </p>
|
||
<dl class="block"><dt class="dlterm"><strong>Parameter Three</strong>: <em>flags </em></dt>
|
||
<dd><ul><li>The <u>flags</u> parameter can additionally be set to special [flags]
|
||
for Substitution by appending [flags] as the third argument to the RewriteRule
|
||
directive. Flags is a comma separated list of the following flags: <dl><dt class="dlterm">redirect|R [=code]</dt>
|
||
<dd>Prefix Substitution with http://thishost[:thisport]/ (which makes the
|
||
new URL a URI) to force a external redirection. If no code is given an HTTP
|
||
response of 302 (MOVED TEMPORARILY) is used. If you want to use other response
|
||
codes in the range 300-400 just specify them as a number or use one of the
|
||
following symbolic names: temp (default), permanent, seeother. Use it for
|
||
rules which should canonicalize the URL and give it back to the client, for
|
||
example, translate ``/~'' into ``/u/'' or always append a slash to /u/user,
|
||
etc. <div class="note"><span class="notetitle">Note:</span> When you use this flag, make sure that the substitution field is
|
||
a valid URL. If not, you are redirecting to an invalid location! And remember
|
||
that this flag itself only prefixes the URL with http://thishost[:thisport]/,
|
||
rewriting continues. Usually you also want to stop and do the redirection
|
||
immediately. To stop the rewriting you also have to provide the 'L' flag.
|
||
</div>
|
||
</dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">forbidden|F</dt>
|
||
<dd>This forces the current URL to be forbidden, for example, it immediately
|
||
sends back an HTTP response of 403 (FORBIDDEN). Use this flag in conjunction
|
||
with appropriate RewriteConds to conditionally block some URLs. </dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">gone|G</dt>
|
||
<dd>This forces the current URL to be gone, for example, it immediately sends
|
||
back an HTTP response of 410 (GONE). Use this flag to mark pages which no
|
||
longer exist as gone. </dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">proxy|P</dt>
|
||
<dd>This flag forces the substitution part to be internally forced as a proxy
|
||
request and immediately (for example, rewriting rule processing stops here)
|
||
put through the <a href="rzaiemod_proxy.htm">proxy module</a>. You have to make sure that the substitution
|
||
string is a valid URI (for example, typically starting with http://hostname)
|
||
which can be handled by HTTP Server proxy module. If not you get an error
|
||
from the proxy module. Use this flag to achieve a more powerful implementation
|
||
of the ProxyPass directive, to map some remote stuff into the name space of
|
||
the local server. <div class="note"><span class="notetitle">Note:</span> To use this functionality make sure you have the proxy
|
||
module loaded into your HTTP Server configuration (for example, via LoadModule
|
||
directive). </div>
|
||
</dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">last|L</dt>
|
||
<dd>Stop the rewriting process here and don't apply any more rewriting rules.
|
||
(This corresponds to the Perl last command or the break command from the C
|
||
language.) Use this flag to prevent the currently rewritten URL from being
|
||
rewritten further by following rules. For example, use it to rewrite the rootpath
|
||
URL ('/') to a real one, for example, '/e/www/'. </dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">next|N</dt>
|
||
<dd>Re-run the rewriting process (starting again with the first rewriting
|
||
rule). Here the URL to match is again not the original URL but the URL from
|
||
the last rewriting rule. (This corresponds to the Perl next command or the
|
||
continue command from the C language.) Use this flag to restart the rewriting
|
||
process, for example, to immediately go to the top of the loop. But be careful
|
||
not to create an infinite loop.</dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">chain|C</dt>
|
||
<dd>This flag chains the current rule with the next rule (which itself can
|
||
be chained with the following rule, etc.). This has the following effect:
|
||
if a rule matches, then processing continues as usual, for example, the flag
|
||
has no effect. If the rule does not match, then all following chained rules
|
||
are skipped. For instance, use it to remove the ``.www'' part inside a per-directory
|
||
rule set when you let an external redirect happen (where the ``.www '' part
|
||
should not occur). </dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">type|T=MIME-type</dt>
|
||
<dd>Force the MIME-type of the target file to be MIME-type. For instance,
|
||
this can be used to simulate the mod_alias directive ScriptAlias which internally
|
||
forces all files inside the mapped directory to have a MIME type of ``application/x-httpd-cgi''. </dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">nosubreq|NS</dt>
|
||
<dd>This flag forces the rewriting engine to skip a rewriting rule if the
|
||
current request is an internal sub-request. For instance, sub-requests occur
|
||
internally in HTTP Server when mod_include tries to find out information about
|
||
possible directory default files (index.xxx). On sub-requests it is not always
|
||
useful and even sometimes causes a failure if the complete set of rules are
|
||
applied. Use this flag to exclude some rules. Whenever you prefix some URLs
|
||
with CGI-scripts to force them to be processed by the CGI-script, the chance
|
||
is high that you will run into problems (or even overhead) on sub-requests.
|
||
In these cases, use this flag. </dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">nocase|NC</dt>
|
||
<dd>This makes the Pattern case insensitive, for example, there is no difference
|
||
between AZ and AZ when Pattern is matched against the current URL. </dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">qsappend|QSA</dt>
|
||
<dd>This flag forces the rewriting engine to append a query string part in
|
||
the substitution string to the existing one instead of replacing it. Use this
|
||
when you want to add more data to the query string via a rewrite rule. </dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">passthrough|PT</dt>
|
||
<dd>This flag forces the rewriting engine to set the URI field of the internal
|
||
request_rec structure to the value of the filename field. This flag is used
|
||
to be able to post-process the output of RewriteRule directives by Alias,
|
||
ScriptAlias, Redirect, etc. - directives from other URI-to-filename translators.
|
||
A trivial example to show the semantics: If you want to rewrite /ABC to /def
|
||
via the rewriting engine of mod_rewrite and then /def to /ghi with mod_alias:<pre class="block">RewriteRule ^/ABC(.*) /def$1 [PT]
|
||
Alias /def /ghi </pre>
|
||
<p>If you omit the PT flag then mod_rewrite will do its job fine,
|
||
for example, it rewrites uri=/ABC/... to filename=/def/... as a full API-compliant
|
||
URI-to-filename translator should do. Then mod_alias comes and tries to do
|
||
a URI-to-filename transition which will not work. </p>
|
||
<div class="note"><span class="notetitle">Note:</span> You have to use
|
||
this flag if you want to intermix directives of different modules which contain
|
||
URL-to-filename translators. The typical example is the use of mod_alias and
|
||
mod_rewrite. </div>
|
||
</dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">skip|S=num</dt>
|
||
<dd>This flag forces the rewriting engine to skip the next num rules in sequence
|
||
when the current rule matches. Use this to make pseudo if-then-else constructs:
|
||
The last rule of the then-clause becomes skip=N where N is the number of rules
|
||
in the else-clause. (This is not the same as the 'chain|C' flag.) </dd>
|
||
</dl>
|
||
<dl><dt class="dlterm">env|E=VAR:VAL</dt>
|
||
<dd>This forces an environment variable named VAR to be set to the value VAL,
|
||
where VAL can contain regexp backreferences $N and %N which will be expanded.
|
||
You can use this flag more than once to set more than one variable. The variables
|
||
can be later dereferenced in many situations, but usually from within SSI
|
||
(via <!--#echo var="VAR"-->) or CGI (for example $ENV{'VAR'}). Additionally
|
||
you can dereference it in a following RewriteCond pattern via %{ENV:VAR}.
|
||
Use this to strip but remember information from URLs. </dd>
|
||
</dl>
|
||
</li>
|
||
</ul>
|
||
</dd>
|
||
</dl>
|
||
<div class="note"><span class="notetitle">Note:</span> Never forget that Pattern is applied to a complete URL in per-server
|
||
configuration files. But in per-directory configuration files, the per-directory
|
||
prefix (which always is the same for a specific directory!) is automatically
|
||
removed for the pattern matching and automatically added after the substitution
|
||
has been done. This feature is essential for many sorts of rewriting, because
|
||
without this prefix stripping you have to match the parent directory which
|
||
is not always possible. There is one exception: If a substitution string starts
|
||
with ``http://'' then the directory prefix will not be added and an external
|
||
redirect or proxy throughput (if flag P is used) is forced. To enable the
|
||
rewriting engine for per-directory configuration files you need to set RewriteEngine
|
||
On in these files and Option FollowSymLinks must be enabled. If the override
|
||
of FollowSymLinks is disabled for a user's directory, then you cannot use
|
||
the rewriting engine. This restriction is needed for security reasons.</div>
|
||
<p><strong>Possible substitution combinations and meanings:</strong> </p>
|
||
|
||
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" frame="border" border="1" rules="all"><thead align="left"><tr><th valign="top" width="42.857142857142854%" id="d0e1191">Given rule</th>
|
||
<th valign="top" width="57.14285714285714%" id="d0e1193">Resulting substitution</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody><tr><td valign="top" width="42.857142857142854%" headers="d0e1191 ">^/somepath(.*) otherpath$1 </td>
|
||
<td valign="top" width="57.14285714285714%" headers="d0e1193 ">not supported </td>
|
||
</tr>
|
||
<tr><td valign="top" width="42.857142857142854%" headers="d0e1191 ">^/somepath(.*) otherpath$1 [R] </td>
|
||
<td valign="top" width="57.14285714285714%" headers="d0e1193 ">not supported </td>
|
||
</tr>
|
||
<tr><td valign="top" width="42.857142857142854%" headers="d0e1191 ">^/somepath(.*) otherpath$1 [P] </td>
|
||
<td valign="top" width="57.14285714285714%" headers="d0e1193 ">not supported </td>
|
||
</tr>
|
||
<tr><td valign="top" width="42.857142857142854%" headers="d0e1191 ">^/somepath(.*) /otherpath$1 </td>
|
||
<td valign="top" width="57.14285714285714%" headers="d0e1193 ">/otherpath/pathinfo </td>
|
||
</tr>
|
||
<tr><td valign="top" width="42.857142857142854%" headers="d0e1191 ">^/somepath(.*) /otherpath$1 [R] </td>
|
||
<td valign="top" width="57.14285714285714%" headers="d0e1193 ">http://thishost/otherpath/pathinfo via external redirection </td>
|
||
</tr>
|
||
<tr><td valign="top" width="42.857142857142854%" headers="d0e1191 ">^/somepath(.*) /otherpath$1 [P] </td>
|
||
<td valign="top" width="57.14285714285714%" headers="d0e1193 ">not supported </td>
|
||
</tr>
|
||
<tr><td valign="top" width="42.857142857142854%" headers="d0e1191 ">^/somepath(.*) http://thishost/otherpath$1 </td>
|
||
<td valign="top" width="57.14285714285714%" headers="d0e1193 ">/otherpath/pathinfo</td>
|
||
</tr>
|
||
<tr><td valign="top" width="42.857142857142854%" headers="d0e1191 ">^/somepath(.*) http://thishost/otherpath$1 [R] </td>
|
||
<td valign="top" width="57.14285714285714%" headers="d0e1193 ">http://thishost/otherpath/pathinfo via external redirection </td>
|
||
</tr>
|
||
<tr><td valign="top" width="42.857142857142854%" headers="d0e1191 ">^/somepath(.*) http://thishost/otherpath$1 [P] </td>
|
||
<td valign="top" width="57.14285714285714%" headers="d0e1193 ">not supported </td>
|
||
</tr>
|
||
<tr><td valign="top" width="42.857142857142854%" headers="d0e1191 ">^/somepath(.*) http://otherhost/otherpath$1 </td>
|
||
<td valign="top" width="57.14285714285714%" headers="d0e1193 ">http://otherhost/otherpath/pathinfo via external redirection </td>
|
||
</tr>
|
||
<tr><td valign="top" width="42.857142857142854%" headers="d0e1191 ">^/somepath(.*) http://otherhost/otherpath$1 [R] </td>
|
||
<td valign="top" width="57.14285714285714%" headers="d0e1193 ">^/somepath(.*) http://otherhost/otherpath$1 [R] </td>
|
||
</tr>
|
||
<tr><td valign="top" width="42.857142857142854%" headers="d0e1191 ">^/somepath(.*) http://otherhost/otherpath$1 [P] </td>
|
||
<td valign="top" width="57.14285714285714%" headers="d0e1193 ">http://otherhost/otherpath/pathinfo via internal proxy </td>
|
||
</tr>
|
||
<tr><td valign="top" width="42.857142857142854%" headers="d0e1191 ">^localpath(.*) otherpath$1 </td>
|
||
<td valign="top" width="57.14285714285714%" headers="d0e1193 ">/somepath/otherpath/pathinfo </td>
|
||
</tr>
|
||
<tr><td valign="top" width="42.857142857142854%" headers="d0e1191 ">^localpath(.*) otherpath$1 [R] </td>
|
||
<td valign="top" width="57.14285714285714%" headers="d0e1193 ">http://thishost/somepath/otherpath/pathinfo via external
|
||
redirection </td>
|
||
</tr>
|
||
<tr><td valign="top" width="42.857142857142854%" headers="d0e1191 ">^localpath(.*) otherpath$1 [P] </td>
|
||
<td valign="top" width="57.14285714285714%" headers="d0e1193 ">not supported </td>
|
||
</tr>
|
||
<tr><td valign="top" width="42.857142857142854%" headers="d0e1191 ">^localpath(.*) /otherpath$1 </td>
|
||
<td valign="top" width="57.14285714285714%" headers="d0e1193 ">/otherpath/pathinfo </td>
|
||
</tr>
|
||
<tr><td valign="top" width="42.857142857142854%" headers="d0e1191 ">^localpath(.*) /otherpath$1 [R] </td>
|
||
<td valign="top" width="57.14285714285714%" headers="d0e1193 ">http://thishost/otherpath/pathinfo via external redirection </td>
|
||
</tr>
|
||
<tr><td valign="top" width="42.857142857142854%" headers="d0e1191 ">^localpath(.*) /otherpath$1 [P] </td>
|
||
<td valign="top" width="57.14285714285714%" headers="d0e1193 ">not supported </td>
|
||
</tr>
|
||
<tr><td valign="top" width="42.857142857142854%" headers="d0e1191 ">^localpath(.*) http://thishost/otherpath$1 </td>
|
||
<td valign="top" width="57.14285714285714%" headers="d0e1193 ">/otherpath/pathinfo </td>
|
||
</tr>
|
||
<tr><td valign="top" width="42.857142857142854%" headers="d0e1191 ">^localpath(.*) http://thishost/otherpath$1 [R] </td>
|
||
<td valign="top" width="57.14285714285714%" headers="d0e1193 ">http://thishost/otherpath/pathinfo via external redirection </td>
|
||
</tr>
|
||
<tr><td valign="top" width="42.857142857142854%" headers="d0e1191 ">^localpath(.*) http://thishost/otherpath$1 [P] </td>
|
||
<td valign="top" width="57.14285714285714%" headers="d0e1193 ">not supported </td>
|
||
</tr>
|
||
<tr><td valign="top" width="42.857142857142854%" headers="d0e1191 ">^localpath(.*) http://otherhost/otherpath$1 </td>
|
||
<td valign="top" width="57.14285714285714%" headers="d0e1193 ">http://otherhost/otherpath/pathinfo via external redirection </td>
|
||
</tr>
|
||
<tr><td valign="top" width="42.857142857142854%" headers="d0e1191 ">^localpath(.*) http://otherhost/otherpath$1 [R] </td>
|
||
<td valign="top" width="57.14285714285714%" headers="d0e1193 ">http://otherhost/otherpath/pathinfo via external redirection
|
||
(the [R] flag is redundant) </td>
|
||
</tr>
|
||
<tr><td valign="top" width="42.857142857142854%" headers="d0e1191 ">^localpath(.*) http://otherhost/otherpath$1 [P] </td>
|
||
<td valign="top" width="57.14285714285714%" headers="d0e1193 ">http://otherhost/otherpath/pathinfo via internal proxy </td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<p>If you wanted to rewrite URLs of the form <tt>/ Language /~ Realname /.../
|
||
File into /u/ Username /.../ File</tt> . Language, you would take the rewrite
|
||
mapfile from above and save it under <tt>/path/to/file/map.txt</tt>. Then
|
||
we only have to add the following lines to HTTP Server configuration file:
|
||
</p>
|
||
<pre class="block">RewriteLog /path/to/file/rewrite.log
|
||
RewriteMap real-to-user txt:/path/to/file/map.txt
|
||
RewriteRule ^/([^/]+)/~([^/]+)/(.*)$ /u/${real-to-user:$2|nobody}/$3.$1</pre>
|
||
</div>
|
||
</div>
|
||
|
||
</body>
|
||
</html> |