2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
7 Licensed to the Apache Software Foundation (ASF) under one or more
8 contributor license agreements. See the NOTICE file distributed with
9 this work for additional information regarding copyright ownership.
10 The ASF licenses this file to You under the Apache License, Version 2.0
11 (the "License"); you may not use this file except in compliance with
12 the License. You may obtain a copy of the License at
14 http://www.apache.org/licenses/LICENSE-2.0
16 Unless required by applicable law or agreed to in writing, software
17 distributed under the License is distributed on an "AS IS" BASIS,
18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 See the License for the specific language governing permissions and
20 limitations under the License.
23 <modulesynopsis metafile="mod_rewrite.xml.meta">
25 <name>mod_rewrite</name>
27 <description>Provides a rule-based rewriting engine to rewrite requested
28 URLs on the fly</description>
30 <status>Extension</status>
31 <sourcefile>mod_rewrite.c</sourcefile>
32 <identifier>rewrite_module</identifier>
35 <p>The <module>mod_rewrite</module> module uses a rule-based rewriting
36 engine, based on a PCRE regular-expression parser, to rewrite requested URLs on
37 the fly. By default, <module>mod_rewrite</module> maps a URL to a filesystem
38 path. However, it can also be used to redirect one URL to another URL, or
39 to invoke an internal proxy fetch.</p>
40 <p><module>mod_rewrite</module> provides a flexible and powerful way to
41 manipulate URLs using an unlimited number of rules. Each rule can have an
42 unlimited number of attached rule conditions, to allow you to rewrite URL
43 based on server variables, environment variables, HTTP headers, or time
45 <p><module>mod_rewrite</module> operates on the full URL path, including the
46 path-info section. A rewrite rule can be invoked in
47 <code>httpd.conf</code> or in <code>.htaccess</code>. The path generated
48 by a rewrite rule can include a query string, or can lead to internal
49 sub-processing, external request redirection, or internal proxy
52 <p>Further details, discussion, and examples, are provided in the
53 <a href="../rewrite/">detailed mod_rewrite documentation</a>.</p>
56 <section id="logging"><title>Logging</title>
58 <p><module>mod_rewrite</module> offers detailed logging of its actions
59 at the <code>trace1</code> to <code>trace8</code> log levels. The
60 log level can be set specifically for <module>mod_rewrite</module>
61 using the <directive module="core">LogLevel</directive> directive: Up to
62 level <code>debug</code>, no actions are logged, while <code>trace8</code>
63 means that practically all actions are logged.</p>
66 Using a high trace log level for <module>mod_rewrite</module>
67 will slow down your Apache HTTP Server dramatically! Use a log
68 level higher than <code>trace2</code> only for debugging!
71 <example><title>Example</title>
72 <highlight language="config">
73 LogLevel alert rewrite:trace3
77 <note><title>RewriteLog</title>
78 <p>Those familiar with earlier versions of
79 <module>mod_rewrite</module> will no doubt be looking for the
80 <code>RewriteLog</code> and <code>RewriteLogLevel</code>
81 directives. This functionality has been completely replaced by the
82 new per-module logging configuration mentioned above.
85 <p>To get just the <module>mod_rewrite</module>-specific log
86 messages, pipe the log file through grep:</p>
88 tail -f error_log|fgrep '[rewrite:'
95 <name>RewriteEngine</name>
96 <description>Enables or disables runtime rewriting engine</description>
97 <syntax>RewriteEngine on|off</syntax>
98 <default>RewriteEngine off</default>
99 <contextlist><context>server config</context><context>virtual host</context>
100 <context>directory</context><context>.htaccess</context></contextlist>
101 <override>FileInfo</override>
105 <p>The <directive>RewriteEngine</directive> directive enables or
106 disables the runtime rewriting engine. If it is set to
107 <code>off</code> this module does no runtime processing at
108 all. It does not even update the <code>SCRIPT_URx</code>
109 environment variables.</p>
111 <p>Use this directive to disable rules in a particular context,
112 rather than commenting out all the <directive
113 module="mod_rewrite">RewriteRule</directive> directives.</p>
115 <p>Note that rewrite configurations are not
116 inherited by virtual hosts. This means that you need to have a
117 <code>RewriteEngine on</code> directive for each virtual host
118 in which you wish to use rewrite rules.</p>
120 <p><directive>RewriteMap</directive> directives of the type <code>prg</code>
121 are not started during server initialization if they're defined in a
122 context that does not have <directive>RewriteEngine</directive> set to
129 <name>RewriteOptions</name>
130 <description>Sets some special options for the rewrite engine</description>
131 <syntax>RewriteOptions <var>Options</var></syntax>
132 <contextlist><context>server config</context><context>virtual host</context>
133 <context>directory</context><context>.htaccess</context></contextlist>
134 <override>FileInfo</override>
137 <p>The <directive>RewriteOptions</directive> directive sets some
138 special options for the current per-server or per-directory
139 configuration. The <em>Option</em> string can currently
140 only be one of the following:</p>
143 <dt><code>Inherit</code></dt>
146 <p>This forces the current configuration to inherit the
147 configuration of the parent. In per-virtual-server context,
148 this means that the maps, conditions and rules of the main
149 server are inherited. In per-directory context this means
150 that conditions and rules of the parent directory's
151 <code>.htaccess</code> configuration or
152 <directive type="section" module="core">Directory</directive>
153 sections are inherited. The inherited rules are virtually copied
154 to the section where this directive is being used. If used in
155 combination with local rules, the inherited rules are copied behind
156 the local rules. The position of this directive - below or above
157 of local rules - has no influence on this behavior. If local
158 rules forced the rewriting to stop, the inherited rules won't
161 <note type="warning">
162 Rules inherited from the parent scope are applied
163 <strong>after</strong> rules specified in the child scope.
167 <dt><code>InheritBefore</code></dt>
169 <p> Like <code>Inherit</code> above, but the rules from the parent scope
170 are applied <strong>before</strong> rules specified in the child scope.<br />
171 Available in Apache HTTP Server 2.3.10 and later.</p>
174 <dt><code>InheritDown</code></dt>
177 <p>If this option is enabled, all child configurations will inherit
178 the configuration of the current configuration. It is equivalent to
179 specifying <code>RewriteOptions Inherit</code> in all child
180 configurations. See the <code>Inherit</code> option for more details
181 on how the parent-child relationships are handled.<br />
182 Available in Apache HTTP Server 2.4.8 and later.</p>
185 <dt><code>InheritDownBefore</code></dt>
188 <p>Like <code>InheritDown</code> above, but the rules from the current
189 scope are applied <strong>before</strong> rules specified in any child's
191 Available in Apache HTTP Server 2.4.8 and later.</p>
194 <dt><code>IgnoreInherit</code></dt>
197 <p>This option forces the current and child configurations to ignore
198 all rules that would be inherited from a parent specifying
199 <code>InheritDown</code> or <code>InheritDownBefore</code>.<br />
200 Available in Apache HTTP Server 2.4.8 and later.</p>
203 <dt><code>AllowNoSlash</code></dt>
205 <p>By default, <module>mod_rewrite</module> will ignore URLs that map to a
206 directory on disk but lack a trailing slash, in the expectation that
207 the <module>mod_dir</module> module will issue the client with a redirect to
208 the canonical URL with a trailing slash.</p>
210 <p>When the <directive module="mod_dir">DirectorySlash</directive> directive
211 is set to off, the <code>AllowNoSlash</code> option can be enabled to ensure
212 that rewrite rules are no longer ignored. This option makes it possible to
213 apply rewrite rules within .htaccess files that match the directory without
214 a trailing slash, if so desired.<br />
215 Available in Apache HTTP Server 2.4.0 and later.</p>
218 <dt><code>AllowAnyURI</code></dt>
221 <p>When <directive module="mod_rewrite">RewriteRule</directive>
222 is used in <code>VirtualHost</code> or server context with
223 version 2.2.22 or later of httpd, <module>mod_rewrite</module>
224 will only process the rewrite rules if the request URI is a <a
225 href="directive-dict.html#Syntax">URL-path</a>. This avoids
226 some security issues where particular rules could allow
227 "surprising" pattern expansions (see <a
228 href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-3368">CVE-2011-3368</a>
230 href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-4317">CVE-2011-4317</a>).
231 To lift the restriction on matching a URL-path, the
232 <code>AllowAnyURI</code> option can be enabled, and
233 <module>mod_rewrite</module> will apply the rule set to any
234 request URI string, regardless of whether that string matches
235 the URL-path grammar required by the HTTP specification.<br />
236 Available in Apache HTTP Server 2.4.3 and later.</p>
238 <note type="warning">
239 <title>Security Warning</title>
241 <p>Enabling this option will make the server vulnerable to
242 security issues if used with rewrite rules which are not
243 carefully authored. It is <strong>strongly recommended</strong>
244 that this option is not used. In particular, beware of input
245 strings containing the '<code>@</code>' character which could
246 change the interpretation of the transformed URI, as per the
251 <dt><code>MergeBase</code></dt>
254 <p>With this option, the value of <directive module="mod_rewrite"
255 >RewriteBase</directive> is copied from where it's explicitly defined
256 into any sub-directory or sub-location that doesn't define its own
257 <directive module="mod_rewrite">RewriteBase</directive>. This was the
258 default behavior in 2.4.0 through 2.4.3, and the flag to restore it is
259 available Apache HTTP Server 2.4.4 and later.</p>
262 <dt><code>IgnoreContextInfo</code></dt>
265 <p>When a relative substitution is made
266 in directory (htaccess) context and <directive module="mod_rewrite"
267 >RewriteBase</directive> has not been set, this module uses some
268 extended URL and filesystem context information to change the
269 relative substitution back into a URL. Modules such as
270 <module>mod_userdir</module> and <module>mod_alias</module>
271 supply this extended context info. </p>
280 <name>RewriteMap</name>
281 <description>Defines a mapping function for key-lookup</description>
282 <syntax>RewriteMap <em>MapName</em> <em>MapType</em>:<em>MapSource</em>
283 <em>MapTypeOptions</em>
285 <contextlist><context>server config</context><context>virtual host</context>
289 <p>The <directive>RewriteMap</directive> directive defines a
290 <em>Rewriting Map</em> which can be used inside rule
291 substitution strings by the mapping-functions to
292 insert/substitute fields through a key lookup. The source of
293 this lookup can be of various types.</p>
295 <p>The <a id="mapfunc" name="mapfunc"><em>MapName</em></a> is
296 the name of the map and will be used to specify a
297 mapping-function for the substitution strings of a rewriting
298 rule via one of the following constructs:</p>
301 <strong><code>${</code> <em>MapName</em> <code>:</code>
302 <em>LookupKey</em> <code>}</code><br />
303 <code>${</code> <em>MapName</em> <code>:</code>
304 <em>LookupKey</em> <code>|</code> <em>DefaultValue</em>
305 <code>}</code></strong>
308 <p>When such a construct occurs, the map <em>MapName</em> is
309 consulted and the key <em>LookupKey</em> is looked-up. If the
310 key is found, the map-function construct is substituted by
311 <em>SubstValue</em>. If the key is not found then it is
312 substituted by <em>DefaultValue</em> or by the empty string
313 if no <em>DefaultValue</em> was specified. Empty values
314 behave as if the key was absent, therefore it is not possible
315 to distinguish between empty-valued keys and absent keys.</p>
317 <p>For example, you might define a
318 <directive>RewriteMap</directive> as:</p>
320 <highlight language="config">
321 RewriteMap examplemap txt:/path/to/file/map.txt
324 <p>You would then be able to use this map in a
325 <directive>RewriteRule</directive> as follows:</p>
327 <highlight language="config">
328 RewriteRule ^/ex/(.*) ${examplemap:$1}
331 <p>The meaning of the <em>MapTypeOptions</em> argument depends on
332 particular <em>MapType</em>. See the
333 <a href="../rewrite/rewritemap.html">Using RewriteMap</a> for
334 more information.</p>
336 <p>The following combinations for <em>MapType</em> and
337 <em>MapSource</em> can be used:</p>
342 <dd>A plain text file containing space-separated key-value
343 pairs, one per line. (<a href="../rewrite/rewritemap.html#txt">Details ...</a>)</dd>
346 <dd>Randomly selects an entry from a plain text file (<a href="../rewrite/rewritemap.html#rnd">Details ...</a>)</dd>
349 <dd>Looks up an entry in a dbm file containing name, value
350 pairs. Hash is constructed from a plain text file format using
351 the <code><a href="../programs/httxt2dbm.html">httxt2dbm</a></code>
352 utility. (<a href="../rewrite/rewritemap.html#dbm">Details ...</a>)</dd>
355 <dd>One of the four available internal functions provided by
356 <code>RewriteMap</code>: toupper, tolower, escape or
357 unescape. (<a href="../rewrite/rewritemap.html#int">Details ...</a>)</dd>
360 <dd>Calls an external program or script to process the
361 rewriting. (<a href="../rewrite/rewritemap.html#prg">Details ...</a>)</dd>
363 <dt>dbd or fastdbd</dt>
364 <dd>A SQL SELECT statement to be performed to look up the
365 rewrite target. (<a href="../rewrite/rewritemap.html#dbd">Details ...</a>)</dd>
368 <p>Further details, and numerous examples, may be found in the <a
369 href="../rewrite/rewritemap.html">RewriteMap HowTo</a></p>
375 <name>RewriteBase</name>
376 <description>Sets the base URL for per-directory rewrites</description>
377 <syntax>RewriteBase <em>URL-path</em></syntax>
378 <default>None</default>
379 <contextlist><context>directory</context><context>.htaccess</context>
381 <override>FileInfo</override>
384 <p>The <directive>RewriteBase</directive> directive specifies the
385 URL prefix to be used for per-directory (htaccess)
386 <directive>RewriteRule</directive> directives that substitute a relative
388 <p> This directive is <em>required</em> when you use a relative path
389 in a substitution in per-directory (htaccess) context unless either
390 of the following conditions are true:</p>
392 <li> The original request, and the substitution, are underneath the
393 <directive module="core">DocumentRoot</directive>
394 (as opposed to reachable by other means, such as
395 <directive module="mod_alias">Alias</directive>).</li>
396 <li> The <em>filesystem</em> path to the directory containing the
397 <directive>RewriteRule</directive>, suffixed by the relative
398 substitution is also valid as a URL path on the server
400 <li> In Apache HTTP Server 2.4.11 and later, this directive may be
401 omitted when the request is mapped via
402 <directive module="mod_alias">Alias</directive>
403 or <module>mod_userdir</module>.</li>
406 <p> In the example below, <directive>RewriteBase</directive> is necessary
407 to avoid rewriting to http://example.com/opt/myapp-1.2.3/welcome.html
408 since the resource was not relative to the document root. This
409 misconfiguration would normally cause the server to look for an "opt"
410 directory under the document root.</p>
411 <highlight language="config">
412 DocumentRoot /var/www/example.com
413 AliasMatch "^/myapp" "/opt/myapp-1.2.3"
414 <Directory "/opt/myapp-1.2.3">
417 RewriteRule ^index\.html$ welcome.html
426 <name>RewriteCond</name>
427 <description>Defines a condition under which rewriting will take place
430 <em>TestString</em> <em>CondPattern</em></syntax>
431 <contextlist><context>server config</context><context>virtual host</context>
432 <context>directory</context><context>.htaccess</context></contextlist>
433 <override>FileInfo</override>
436 <p>The <directive>RewriteCond</directive> directive defines a
437 rule condition. One or more <directive>RewriteCond</directive>
438 can precede a <directive module="mod_rewrite">RewriteRule</directive>
439 directive. The following rule is then only used if both
440 the current state of the URI matches its pattern, <strong
441 >and</strong> if these conditions are met.</p>
443 <p><em>TestString</em> is a string which can contain the
444 following expanded constructs in addition to plain text:</p>
448 <strong>RewriteRule backreferences</strong>: These are
449 backreferences of the form <strong><code>$N</code></strong>
450 (0 <= N <= 9). $1 to $9 provide access to the grouped
451 parts (in parentheses) of the pattern, from the
452 <code>RewriteRule</code> which is subject to the current
453 set of <code>RewriteCond</code> conditions. $0 provides
454 access to the whole string matched by that pattern.
457 <strong>RewriteCond backreferences</strong>: These are
458 backreferences of the form <strong><code>%N</code></strong>
459 (0 <= N <= 9). %1 to %9 provide access to the grouped
460 parts (again, in parentheses) of the pattern, from the last matched
461 <code>RewriteCond</code> in the current set
462 of conditions. %0 provides access to the whole string matched by
466 <strong>RewriteMap expansions</strong>: These are
467 expansions of the form <strong><code
468 >${mapname:key|default}</code></strong>.
469 See <a href="#mapfunc">the documentation for
470 RewriteMap</a> for more details.
473 <strong>Server-Variables</strong>: These are variables of
475 <strong><code>%{</code> <em>NAME_OF_VARIABLE</em>
476 <code>}</code></strong>
477 where <em>NAME_OF_VARIABLE</em> can be a string taken
478 from the following list:
481 <columnspec><column width=".3"/><column width=".3"/>
482 <column width=".3"/></columnspec>
484 <th>HTTP headers:</th> <th>connection & request:</th> <th></th>
493 HTTP_PROXY_CONNECTION<br />
495 HTTP_USER_AGENT<br />
500 CONN_REMOTE_ADDR<br />
502 CONTEXT_DOCUMENT_ROOT<br />
512 SCRIPT_FILENAME<br />
519 <th>server internals:</th> <th>date and time:</th> <th>specials:</th>
531 SERVER_PROTOCOL<br />
532 SERVER_SOFTWARE<br />
548 CONN_REMOTE_ADDR<br />
552 REQUEST_FILENAME<br />
560 <p>These variables all
561 correspond to the similarly named HTTP
562 MIME-headers, C variables of the Apache HTTP Server or
563 <code>struct tm</code> fields of the Unix system.
564 Most are documented <a href="../expr.html#vars">here</a>
565 or elsewhere in the Manual or in the CGI specification.</p>
567 <p>SERVER_NAME and SERVER_PORT depend on the values of
568 <directive module="core">UseCanonicalName</directive> and
569 <directive module="core">UseCanonicalPhysicalPort</directive>
572 <p>Those that are special to mod_rewrite include those below.</p>
575 <dt><code>API_VERSION</code></dt>
577 <dd>This is the version of the Apache httpd module API
578 (the internal interface between server and
579 module) in the current httpd build, as defined in
580 include/ap_mmn.h. The module API version
581 corresponds to the version of Apache httpd in use (in
582 the release version of Apache httpd 1.3.14, for
583 instance, it is 19990320:10), but is mainly of
584 interest to module authors.</dd>
586 <dt><code>CONN_REMOTE_ADDR</code></dt>
588 <dd>Since 2.4.8: The peer IP address of the connection (see the
589 <module>mod_remoteip</module> module).</dd>
591 <dt><code>HTTPS</code></dt>
593 <dd>Will contain the text "on" if the connection is
594 using SSL/TLS, or "off" otherwise. (This variable
595 can be safely used regardless of whether or not
596 <module>mod_ssl</module> is loaded).</dd>
598 <dt><code>IS_SUBREQ</code></dt>
600 <dd>Will contain the text "true" if the request
601 currently being processed is a sub-request,
602 "false" otherwise. Sub-requests may be generated
603 by modules that need to resolve additional files
604 or URIs in order to complete their tasks.</dd>
606 <dt><code>REMOTE_ADDR</code></dt>
608 <dd>The IP address of the remote host (see the
609 <module>mod_remoteip</module> module).</dd>
611 <dt><code>REQUEST_FILENAME</code></dt>
613 <dd>The full local filesystem path to the file or
614 script matching the request, if this has already
615 been determined by the server at the time
616 <code>REQUEST_FILENAME</code> is referenced. Otherwise,
617 such as when used in virtual host context, the same
618 value as <code>REQUEST_URI</code>. Depending on the value of
619 <directive module="core">AcceptPathInfo</directive>, the
620 server may have only used some leading components of the
621 <code>REQUEST_URI</code> to map the request to a file.
624 <dt><code>REQUEST_SCHEME</code></dt>
626 <dd>Will contain the scheme of the request (usually
627 "http" or "https"). This value can be influenced with
628 <directive module="core">ServerName</directive>.</dd>
630 <dt><code>REQUEST_URI</code></dt>
632 <dd>The path component of the requested URI,
633 such as "/index.html". This notably excludes the
634 query string which is available as as its own variable
635 named <code>QUERY_STRING</code>.</dd>
637 <dt><code>THE_REQUEST</code></dt>
639 <dd>The full HTTP request line sent by the
640 browser to the server (e.g., "<code>GET
641 /index.html HTTP/1.1</code>"). This does not
642 include any additional headers sent by the
643 browser. This value has not been unescaped
644 (decoded), unlike most other variables below.</dd>
651 <p>If the <em>TestString</em> has the special value <code>expr</code>,
652 the <em>CondPattern</em> will be treated as an
653 <a href="../expr.html">ap_expr</a>. HTTP headers referenced in the
654 expression will be added to the Vary header if the <code>novary</code>
655 flag is not given.</p>
657 <p>Other things you should be aware of:</p>
661 <p>The variables SCRIPT_FILENAME and REQUEST_FILENAME
662 contain the same value - the value of the
663 <code>filename</code> field of the internal
664 <code>request_rec</code> structure of the Apache HTTP Server.
665 The first name is the commonly known CGI variable name
666 while the second is the appropriate counterpart of
667 REQUEST_URI (which contains the value of the
668 <code>uri</code> field of <code>request_rec</code>).</p>
669 <p>If a substitution occurred and the rewriting continues,
670 the value of both variables will be updated accordingly.</p>
671 <p>If used in per-server context (<em>i.e.</em>, before the
672 request is mapped to the filesystem) SCRIPT_FILENAME and
673 REQUEST_FILENAME cannot contain the full local filesystem
674 path since the path is unknown at this stage of processing.
675 Both variables will initially contain the value of REQUEST_URI
676 in that case. In order to obtain the full local filesystem
677 path of the request in per-server context, use an URL-based
678 look-ahead <code>%{LA-U:REQUEST_FILENAME}</code> to determine
679 the final value of REQUEST_FILENAME.</p></li>
682 <code>%{ENV:variable}</code>, where <em>variable</em> can be
683 any environment variable, is also available.
684 This is looked-up via internal
685 Apache httpd structures and (if not found there) via
686 <code>getenv()</code> from the Apache httpd server process.</li>
689 <code>%{SSL:variable}</code>, where <em>variable</em> is the
690 name of an <a href="mod_ssl.html#envvars">SSL environment
691 variable</a>, can be used whether or not
692 <module>mod_ssl</module> is loaded, but will always expand to
693 the empty string if it is not. Example:
694 <code>%{SSL:SSL_CIPHER_USEKEYSIZE}</code> may expand to
695 <code>128</code>.</li>
698 <code>%{HTTP:header}</code>, where <em>header</em> can be
699 any HTTP MIME-header name, can always be used to obtain the
700 value of a header sent in the HTTP request.
701 Example: <code>%{HTTP:Proxy-Connection}</code> is
702 the value of the HTTP header
703 ``<code>Proxy-Connection:</code>''.
704 <p>If a HTTP header is used in a condition this header is added to
705 the Vary header of the response in case the condition evaluates
706 to true for the request. It is <strong>not</strong> added if the
707 condition evaluates to false for the request. Adding the HTTP header
708 to the Vary header of the response is needed for proper caching.</p>
709 <p>It has to be kept in mind that conditions follow a short circuit
710 logic in the case of the '<strong><code>ornext|OR</code></strong>' flag
711 so that certain conditions might not be evaluated at all.</p></li>
714 <a id="LA-U" name="LA-U"><code>%{LA-U:variable}</code></a>
715 can be used for look-aheads which perform
716 an internal (URL-based) sub-request to determine the final
717 value of <em>variable</em>. This can be used to access
718 variable for rewriting which is not available at the current
719 stage, but will be set in a later phase.
720 <p>For instance, to rewrite according to the
721 <code>REMOTE_USER</code> variable from within the
722 per-server context (<code>httpd.conf</code> file) you must
723 use <code>%{LA-U:REMOTE_USER}</code> - this
724 variable is set by the authorization phases, which come
725 <em>after</em> the URL translation phase (during which mod_rewrite
727 <p>On the other hand, because mod_rewrite implements
728 its per-directory context (<code>.htaccess</code> file) via
729 the Fixup phase of the API and because the authorization
730 phases come <em>before</em> this phase, you just can use
731 <code>%{REMOTE_USER}</code> in that context.</p></li>
734 <code>%{LA-F:variable}</code> can be used to perform an internal
735 (filename-based) sub-request, to determine the final value
736 of <em>variable</em>. Most of the time, this is the same as
740 <p><em>CondPattern</em> is the condition pattern,
741 a regular expression which is applied to the
742 current instance of the <em>TestString</em>.
743 <em>TestString</em> is first evaluated, before being matched against
744 <em>CondPattern</em>.</p>
746 <p><em>CondPattern</em> is usually a
747 <em>perl compatible regular expression</em>, but there is
748 additional syntax available to perform other useful tests against
749 the <em>Teststring</em>:</p>
752 <li>You can prefix the pattern string with a
753 '<code>!</code>' character (exclamation mark) to negate the result
754 of the condition, no matter what kind of <em>CondPattern</em> is used.
758 You can perform lexicographical string comparisons:
761 <li>'<strong><CondPattern</strong>' (lexicographically
763 Treats the <em>CondPattern</em> as a plain string and
764 compares it lexicographically to <em>TestString</em>. True if
765 <em>TestString</em> lexicographically precedes
766 <em>CondPattern</em>.</li>
768 <li>'<strong>>CondPattern</strong>' (lexicographically
770 Treats the <em>CondPattern</em> as a plain string and
771 compares it lexicographically to <em>TestString</em>. True if
772 <em>TestString</em> lexicographically follows
773 <em>CondPattern</em>.</li>
775 <li>'<strong>=CondPattern</strong>' (lexicographically
777 Treats the <em>CondPattern</em> as a plain string and
778 compares it lexicographically to <em>TestString</em>. True if
779 <em>TestString</em> is lexicographically equal to
780 <em>CondPattern</em> (the two strings are exactly
781 equal, character for character). If <em>CondPattern</em>
782 is <code>""</code> (two quotation marks) this
783 compares <em>TestString</em> to the empty string.</li>
785 <li>'<strong><=CondPattern</strong>' (lexicographically
786 less than or equal to)<br />
787 Treats the <em>CondPattern</em> as a plain string and
788 compares it lexicographically to <em>TestString</em>. True
789 if <em>TestString</em> lexicographically precedes
790 <em>CondPattern</em>, or is equal to <em>CondPattern</em>
791 (the two strings are equal, character for character).</li>
793 <li>'<strong>>=CondPattern</strong>' (lexicographically
794 greater than or equal to)<br />
795 Treats the <em>CondPattern</em> as a plain string and
796 compares it lexicographically to <em>TestString</em>. True
797 if <em>TestString</em> lexicographically follows
798 <em>CondPattern</em>, or is equal to <em>CondPattern</em>
799 (the two strings are equal, character for character).</li>
803 You can perform integer comparisons:
806 <li>'<strong>-eq</strong>' (is numerically
807 <strong>eq</strong>ual to)<br />
808 The <em>TestString</em> is treated as an integer, and is
809 numerically compared to the <em>CondPattern</em>. True if
810 the two are numerically equal.</li>
812 <li>'<strong>-ge</strong>' (is numerically
813 <strong>g</strong>reater than or <strong>e</strong>qual to)<br />
814 The <em>TestString</em> is treated as an integer, and is
815 numerically compared to the <em>CondPattern</em>. True if
816 the <em>TestString</em> is numerically greater than or equal
817 to the <em>CondPattern</em>.</li>
819 <li>'<strong>-gt</strong>' (is numerically
820 <strong>g</strong>reater <strong>t</strong>han)<br />
821 The <em>TestString</em> is treated as an integer, and is
822 numerically compared to the <em>CondPattern</em>. True if
823 the <em>TestString</em> is numerically greater than
824 the <em>CondPattern</em>.</li>
826 <li>'<strong>-le</strong>' (is numerically
827 <strong>l</strong>ess than or <strong>e</strong>qual to)<br />
828 The <em>TestString</em> is treated as an integer, and is
829 numerically compared to the <em>CondPattern</em>. True if
830 the <em>TestString</em> is numerically less than or equal
831 to the <em>CondPattern</em>. Avoid confusion with the
832 <strong>-l</strong> by using the <strong>-L</strong> or
833 <strong>-h</strong> variant.</li>
835 <li>'<strong>-lt</strong>' (is numerically
836 <strong>l</strong>ess <strong>t</strong>han)<br />
837 The <em>TestString</em> is treated as an integer, and is
838 numerically compared to the <em>CondPattern</em>. True if
839 the <em>TestString</em> is numerically less than
840 the <em>CondPattern</em>. Avoid confusion with the
841 <strong>-l</strong> by using the <strong>-L</strong> or
842 <strong>-h</strong> variant.</li>
847 <li>You can perform various file attribute tests:
849 <li>'<strong>-d</strong>' (is
850 <strong>d</strong>irectory)<br />
851 Treats the <em>TestString</em> as a pathname and tests
852 whether or not it exists, and is a directory.</li>
854 <li>'<strong>-f</strong>' (is regular
855 <strong>f</strong>ile)<br />
856 Treats the <em>TestString</em> as a pathname and tests
857 whether or not it exists, and is a regular file.</li>
859 <li>'<strong>-F</strong>' (is existing file, via
861 Checks whether or not <em>TestString</em> is a valid file,
862 accessible via all the server's currently-configured
863 access controls for that path. This uses an internal
864 subrequest to do the check, so use it with care -
865 it can impact your server's performance!</li>
867 <li>'<strong>-H</strong>' (is symbolic link, bash convention)<br />
868 See <strong>-l</strong>.</li>
870 <li>'<strong>-l</strong>' (is symbolic
871 <strong>l</strong>ink)<br />
872 Treats the <em>TestString</em> as a pathname and tests
873 whether or not it exists, and is a symbolic link. May also
874 use the bash convention of <strong>-L</strong> or
875 <strong>-h</strong> if there's a possibility of confusion
876 such as when using the <strong>-lt</strong> or
877 <strong>-le</strong> tests.</li>
879 <li>'<strong>-L</strong>' (is symbolic link, bash convention)<br />
880 See <strong>-l</strong>.</li>
882 <li>'<strong>-s</strong>' (is regular file, with
883 <strong>s</strong>ize)<br />
884 Treats the <em>TestString</em> as a pathname and tests
885 whether or not it exists, and is a regular file with size greater
888 <li><p>'<strong>-U</strong>' (is existing URL, via
890 Checks whether or not <em>TestString</em> is a valid URL,
891 accessible via all the server's currently-configured
892 access controls for that path. This uses an internal
893 subrequest to do the check, so use it with care -
894 it can impact your server's performance!</p>
895 <p> This flag <em>only</em> returns information about things
896 like access control, authentication, and authorization. This flag
897 <em>does not</em> return information about the status code the
898 configured handler (static file, CGI, proxy, etc.) would have
901 <li>'<strong>-x</strong>' (has e<strong>x</strong>ecutable
903 Treats the <em>TestString</em> as a pathname and tests
904 whether or not it exists, and has executable permissions.
905 These permissions are determined according to
906 the underlying OS.</li>
913 <p>If the <em>TestString</em> has the special value <code>expr</code>, the
914 <em>CondPattern</em> will be treated as an
915 <a href="../expr.html">ap_expr</a>.</p>
918 In the below example, <code>-strmatch</code> is used to
919 compare the <code>REFERER</code> against the site hostname,
920 to block unwanted hotlinking.
923 <highlight language="config">
924 RewriteCond expr "! %{HTTP_REFERER} -strmatch '*://%{HTTP_HOST}/*'"<br />
925 RewriteRule ^/images - [F]
929 <li>You can also set special flags for
930 <em>CondPattern</em> by appending
931 <strong><code>[</code><em>flags</em><code>]</code></strong>
932 as the third argument to the <code>RewriteCond</code>
933 directive, where <em>flags</em> is a comma-separated list of any of the
937 <li>'<strong><code>nocase|NC</code></strong>'
938 (<strong>n</strong>o <strong>c</strong>ase)<br />
939 This makes the test case-insensitive - differences
940 between 'A-Z' and 'a-z' are ignored, both in the
941 expanded <em>TestString</em> and the <em>CondPattern</em>.
942 This flag is effective only for comparisons between
943 <em>TestString</em> and <em>CondPattern</em>. It has no
944 effect on filesystem and subrequest checks.</li>
947 '<strong><code>ornext|OR</code></strong>'
948 (<strong>or</strong> next condition)<br />
949 Use this to combine rule conditions with a local OR
950 instead of the implicit AND. Typical example:
952 <highlight language="config">
953 RewriteCond %{REMOTE_HOST} ^host1 [OR]
954 RewriteCond %{REMOTE_HOST} ^host2 [OR]
955 RewriteCond %{REMOTE_HOST} ^host3
956 RewriteRule ...some special stuff for any of these hosts...
959 Without this flag you would have to write the condition/rule
963 <li>'<strong><code>novary|NV</code></strong>'
964 (<strong>n</strong>o <strong>v</strong>ary)<br />
965 If a HTTP header is used in the condition, this flag prevents
966 this header from being added to the Vary header of the response. <br />
967 Using this flag might break proper caching of the response if
968 the representation of this response varies on the value of this header.
969 So this flag should be only used if the meaning of the Vary header
976 <p><strong>Example:</strong></p>
978 <p>To rewrite the Homepage of a site according to the
979 ``<code>User-Agent:</code>'' header of the request, you can
980 use the following: </p>
982 <highlight language="config">
983 RewriteCond %{HTTP_USER_AGENT} (iPhone|Blackberry|Android)
984 RewriteRule ^/$ /homepage.mobile.html [L]
986 RewriteRule ^/$ /homepage.std.html [L]
989 <p>Explanation: If you use a browser which identifies itself
990 as a mobile browser (note that the example is incomplete, as
991 there are many other mobile platforms), the mobile version of
992 the homepage is served. Otherwise, the standard page is served.
1000 <name>RewriteRule</name>
1001 <description>Defines rules for the rewriting engine</description>
1003 <em>Pattern</em> <em>Substitution</em> [<em>flags</em>]</syntax>
1004 <contextlist><context>server config</context><context>virtual host</context>
1005 <context>directory</context><context>.htaccess</context></contextlist>
1006 <override>FileInfo</override>
1009 <p>The <directive>RewriteRule</directive> directive is the real
1010 rewriting workhorse. The directive can occur more than once,
1011 with each instance defining a single rewrite rule. The
1012 order in which these rules are defined is important - this is the order
1013 in which they will be applied at run-time.</p>
1015 <p><a id="patterns" name="patterns"><em>Pattern</em></a> is
1016 a perl compatible <a id="regexp" name="regexp">regular
1017 expression</a>. On the first RewriteRule, it is matched against
1018 the (%-decoded) <a href="directive-dict.html#Syntax">URL-path</a>
1019 of the request, or, in per-directory context (see below), the URL
1020 path relative to that per-directory context. Subsequent patterns
1021 are matched against the output of the last matching RewriteRule.</p>
1023 <note><title><a id="what_is_matched" name="what_is_matched">What is matched?</a></title>
1024 <p>In <directive module="core">VirtualHost</directive> context,
1025 The <em>Pattern</em> will initially be matched against the part of the
1026 URL after the hostname and port, and before the query string (e.g. "/app1/index.html").</p>
1028 <p>In <directive module="core">Directory</directive> and htaccess context,
1029 the <em>Pattern</em> will initially be matched against the
1030 <em>filesystem</em> path, after removing the prefix that led the server
1031 to the current <directive>RewriteRule</directive> (e.g. "app1/index.html"
1032 or "index.html" depending on where the directives are defined).</p>
1034 <p>If you wish to match against the hostname, port, or query string, use a
1035 <directive module="mod_rewrite">RewriteCond</directive> with the
1036 <code>%{HTTP_HOST}</code>, <code>%{SERVER_PORT}</code>, or
1037 <code>%{QUERY_STRING}</code> variables respectively.</p>
1041 <note><title>Per-directory Rewrites</title>
1043 <li>The rewrite engine may be used in <a
1044 href="../howto/htaccess.html">.htaccess</a> files and in <directive type="section"
1045 module="core">Directory</directive> sections, with some additional
1048 <li>To enable the rewrite engine in this context, you need to set
1049 "<code>RewriteEngine On</code>" <strong>and</strong>
1050 "<code>Options FollowSymLinks</code>" must be enabled. If your
1051 administrator has disabled override of <code>FollowSymLinks</code> for
1052 a user's directory, then you cannot use the rewrite engine. This
1053 restriction is required for security reasons.</li>
1055 <li>When using the rewrite engine in <code>.htaccess</code> files the
1056 per-directory prefix (which always is the same for a specific
1057 directory) is automatically <em>removed</em> for the RewriteRule pattern matching
1058 and automatically <em>added</em> after any relative (not starting with a
1059 slash or protocol name) substitution encounters the end of a rule set.
1060 See the <directive module="mod_rewrite">RewriteBase</directive>
1061 directive for more information regarding what prefix will be added back to
1062 relative substitutions.</li>
1064 <li> If you wish to match against the full URL-path in a per-directory
1065 (htaccess) RewriteRule, use the <code>%{REQUEST_URI}</code> variable in
1066 a <directive>RewriteCond</directive>.</li>
1068 <li>The removed prefix always ends with a slash, meaning the matching occurs against a string which
1069 <em>never</em> has a leading slash. Therefore, a <em>Pattern</em> with <code>^/</code> never
1070 matches in per-directory context.</li>
1072 <li>Although rewrite rules are syntactically permitted in <directive
1073 type="section" module="core">Location</directive> and <directive
1074 type="section" module="core">Files</directive> sections
1075 (including their regular expression counterparts), this
1076 should never be necessary and is unsupported. A likely feature
1077 to break in these contexts is relative substitutions.</li>
1081 <p>For some hints on <glossary ref="regex">regular
1082 expressions</glossary>, see
1083 the <a href="../rewrite/intro.html#regex">mod_rewrite
1084 Introduction</a>.</p>
1086 <p>In mod_rewrite, the NOT character
1087 ('<code>!</code>') is also available as a possible pattern
1088 prefix. This enables you to negate a pattern; to say, for instance:
1089 ``<em>if the current URL does <strong>NOT</strong> match this
1090 pattern</em>''. This can be used for exceptional cases, where
1091 it is easier to match the negative pattern, or as a last
1094 <note><title>Note</title>
1095 When using the NOT character to negate a pattern, you cannot include
1096 grouped wildcard parts in that pattern. This is because, when the
1097 pattern does NOT match (ie, the negation matches), there are no
1098 contents for the groups. Thus, if negated patterns are used, you
1099 cannot use <code>$N</code> in the substitution string!
1102 <p>The <a id="rhs" name="rhs"><em>Substitution</em></a> of a
1103 rewrite rule is the string that replaces the original URL-path that
1104 was matched by <em>Pattern</em>. The <em>Substitution</em> may
1109 <dt>file-system path</dt>
1111 <dd>Designates the location on the file-system of the resource
1112 to be delivered to the client. Substitutions are only
1113 treated as a file-system path when the rule is configured in
1114 server (virtualhost) context and the first component of the
1115 path in the substitution exists in the file-system</dd>
1120 module="core">DocumentRoot</directive>-relative path to the
1121 resource to be served. Note that <module>mod_rewrite</module>
1122 tries to guess whether you have specified a file-system path
1123 or a URL-path by checking to see if the first segment of the
1124 path exists at the root of the file-system. For example, if
1125 you specify a <em>Substitution</em> string of
1126 <code>/www/file.html</code>, then this will be treated as a
1127 URL-path <em>unless</em> a directory named <code>www</code>
1128 exists at the root or your file-system (or, in the case of
1129 using rewrites in a <code>.htaccess</code> file, relative to
1130 your document root), in which case it will
1131 be treated as a file-system path. If you wish other
1132 URL-mapping directives (such as <directive
1133 module="mod_alias">Alias</directive>) to be applied to the
1134 resulting URL-path, use the <code>[PT]</code> flag as
1135 described below.</dd>
1137 <dt>Absolute URL</dt>
1139 <dd>If an absolute URL is specified,
1140 <module>mod_rewrite</module> checks to see whether the
1141 hostname matches the current host. If it does, the scheme and
1142 hostname are stripped out and the resulting path is treated as
1143 a URL-path. Otherwise, an external redirect is performed for
1144 the given URL. To force an external redirect back to the
1145 current host, see the <code>[R]</code> flag below.</dd>
1147 <dt><code>-</code> (dash)</dt>
1149 <dd>A dash indicates that no substitution should be performed
1150 (the existing path is passed through untouched). This is used
1151 when a flag (see below) needs to be applied without changing
1156 <p>In addition to plain text, the <em>Substitution</em> string can include</p>
1159 <li>back-references (<code>$N</code>) to the RewriteRule
1162 <li>back-references (<code>%N</code>) to the last matched
1163 RewriteCond pattern</li>
1165 <li>server-variables as in rule condition test-strings
1166 (<code>%{VARNAME}</code>)</li>
1168 <li><a href="#mapfunc">mapping-function</a> calls
1169 (<code>${mapname:key|default}</code>)</li>
1172 <p>Back-references are identifiers of the form
1173 <code>$</code><strong>N</strong>
1174 (<strong>N</strong>=0..9), which will be replaced
1175 by the contents of the <strong>N</strong>th group of the
1176 matched <em>Pattern</em>. The server-variables are the same
1177 as for the <em>TestString</em> of a <code>RewriteCond</code>
1178 directive. The mapping-functions come from the
1179 <code>RewriteMap</code> directive and are explained there.
1180 These three types of variables are expanded in the order above.</p>
1182 <p>Rewrite rules are applied to the results of previous rewrite
1183 rules, in the order in which they are defined
1184 in the config file. The URL-path or file-system path (see <a
1185 href="#what_is_matched">"What is matched?"</a>, above) is <strong>completely
1186 replaced</strong> by the <em>Substitution</em> and the
1187 rewriting process continues until all rules have been applied,
1188 or it is explicitly terminated by an
1189 <a href="../rewrite/flags.html#flag_l"><code><strong>L</strong></code> flag</a>,
1190 or other flag which implies immediate termination, such as
1191 <code><strong>END</strong></code> or
1192 <code><strong>F</strong></code>.</p>
1194 <note><title>Modifying the Query String</title>
1195 <p>By default, the query string is passed through unchanged. You
1196 can, however, create URLs in the substitution string containing
1197 a query string part. Simply use a question mark inside the
1198 substitution string to indicate that the following text should
1199 be re-injected into the query string. When you want to erase an
1200 existing query string, end the substitution string with just a
1201 question mark. To combine new and old query strings, use the
1202 <code>[QSA]</code> flag.</p>
1205 <p>Additionally you can set special <a name="rewriteflags"
1206 id="rewriteflags">actions</a> to be performed by
1207 appending <strong><code>[</code><em>flags</em><code>]</code></strong>
1208 as the third argument to the <code>RewriteRule</code>
1209 directive. <em>Flags</em> is a comma-separated list, surround by square
1210 brackets, of any of the flags in the following table. More
1211 details, and examples, for each flag, are available in the <a
1212 href="../rewrite/flags.html">Rewrite Flags document</a>.</p>
1214 <table border="1" style="zebra">
1215 <tr><th>Flag and syntax</th>
1220 <td>Escape non-alphanumeric characters in backreferences <em>before</em>
1221 applying the transformation. <em><a
1222 href="../rewrite/flags.html#flag_b">details ...</a></em></td>
1225 <td>backrefnoplus|BNP</td>
1226 <td>If backreferences are being escaped, spaces should be escaped to
1227 %20 instead of +. Useful when the backreference will be used in the
1228 path component rather than the query string.<em><a
1229 href="../rewrite/flags.html#flag_bnp">details ...</a></em></td>
1234 <td>Rule is chained to the following rule. If the rule fails,
1235 the rule(s) chained to it will be skipped. <em><a
1236 href="../rewrite/flags.html#flag_c">details ...</a></em></td>
1239 <td>cookie|CO=<em>NAME</em>:<em>VAL</em></td>
1240 <td>Sets a cookie in the client browser. Full syntax is:
1241 CO=<em>NAME</em>:<em>VAL</em>:<em>domain</em>[:<em>lifetime</em>[:<em>path</em>[:<em>secure</em>[:<em>httponly</em>]]]] <em><a href="../rewrite/flags.html#flag_co">details ...</a></em>
1245 <td>discardpath|DPI</td>
1246 <td>Causes the PATH_INFO portion of the rewritten URI to be
1247 discarded. <em><a href="../rewrite/flags.html#flag_dpi">details
1252 <td>Stop the rewriting process immediately and don't apply any
1253 more rules. Also prevents further execution of rewrite rules
1254 in per-directory and .htaccess context. (Available in 2.3.9 and later)
1255 <em><a href="../rewrite/flags.html#flag_end">details ...</a></em></td>
1258 <td>env|E=[!]<em>VAR</em>[:<em>VAL</em>]</td>
1259 <td>Causes an environment variable <em>VAR</em> to be set (to the
1260 value <em>VAL</em> if provided). The form !<em>VAR</em> causes
1261 the environment variable <em>VAR</em> to be unset.
1262 <em><a href="../rewrite/flags.html#flag_e">details ...</a></em></td>
1265 <td>forbidden|F</td>
1266 <td>Returns a 403 FORBIDDEN response to the client browser.
1267 <em><a href="../rewrite/flags.html#flag_f">details ...</a></em></td>
1271 <td>Returns a 410 GONE response to the client browser. <em><a
1272 href="../rewrite/flags.html#flag_g">details ...</a></em></td>
1275 <td>Handler|H=<em>Content-handler</em></td>
1276 <td>Causes the resulting URI to be sent to the specified
1277 <em>Content-handler</em> for processing. <em><a
1278 href="../rewrite/flags.html#flag_h">details ...</a></em></td>
1282 <td>Stop the rewriting process immediately and don't apply any
1283 more rules. Especially note caveats for per-directory and
1284 .htaccess context (see also the END flag). <em><a
1285 href="../rewrite/flags.html#flag_l">details ...</a></em></td>
1289 <td>Re-run the rewriting process, starting again with the first
1290 rule, using the result of the ruleset so far as a starting
1291 point. <em><a href="../rewrite/flags.html#flag_n">details
1296 <td>Makes the pattern comparison case-insensitive.
1297 <em><a href="../rewrite/flags.html#flag_nc">details ...</a></em></td>
1300 <td>noescape|NE</td>
1301 <td>Prevent mod_rewrite from applying hexcode escaping of
1302 special characters in the result of the rewrite. <em><a
1303 href="../rewrite/flags.html#flag_ne">details ...</a></em></td>
1306 <td>nosubreq|NS</td>
1307 <td>Causes a rule to be skipped if the current request is an
1308 internal sub-request. <em><a
1309 href="../rewrite/flags.html#flag_ns">details ...</a></em></td>
1313 <td>Force the substitution URL to be internally sent as a proxy
1314 request. <em><a href="../rewrite/flags.html#flag_p">details
1318 <td>passthrough|PT</td>
1319 <td>Forces the resulting URI to be passed back to the URL
1320 mapping engine for processing of other URI-to-filename
1321 translators, such as <code>Alias</code> or
1322 <code>Redirect</code>. <em><a
1323 href="../rewrite/flags.html#flag_pt">details ...</a></em></td>
1326 <td>qsappend|QSA</td>
1327 <td>Appends any query string from the original request URL to
1328 any query string created in the rewrite target.<em><a
1329 href="../rewrite/flags.html#flag_qsa">details ...</a></em></td>
1332 <td>qsdiscard|QSD</td>
1333 <td>Discard any query string attached to the incoming URI.
1334 <em><a href="../rewrite/flags.html#flag_qsd">details
1338 <td>redirect|R[=<em>code</em>]</td>
1339 <td>Forces an external redirect, optionally with the specified
1340 HTTP status code. <em><a
1341 href="../rewrite/flags.html#flag_r">details ...</a></em>
1345 <td>skip|S=<em>num</em></td>
1346 <td>Tells the rewriting engine to skip the next <em>num</em>
1347 rules if the current rule matches. <em><a
1348 href="../rewrite/flags.html#flag_s">details ...</a></em></td>
1351 <td>type|T=<em>MIME-type</em></td>
1352 <td>Force the <glossary>MIME-type</glossary> of the target file
1353 to be the specified type. <em><a
1354 href="../rewrite/flags.html#flag_t">details ...</a></em></td>
1358 <note><title>Home directory expansion</title>
1359 <p> When the substitution string begins with a string
1360 resembling "/~user" (via explicit text or backreferences), mod_rewrite performs
1361 home directory expansion independent of the presence or configuration
1362 of <module>mod_userdir</module>.</p>
1364 <p> This expansion does not occur when the <em>PT</em>
1365 flag is used on the <directive module="mod_rewrite">RewriteRule</directive>
1370 <p>Here are all possible substitution combinations and their
1373 <p><strong>Inside per-server configuration
1374 (<code>httpd.conf</code>)<br />
1375 for request ``<code>GET
1376 /somepath/pathinfo</code>'':</strong><br />
1379 <table border="1" style="zebra">
1382 <th>Resulting Substitution</th>
1386 <td>^/somepath(.*) otherpath$1</td>
1387 <td>invalid, not supported</td>
1391 <td>^/somepath(.*) otherpath$1 [R]</td>
1392 <td>invalid, not supported</td>
1396 <td>^/somepath(.*) otherpath$1 [P]</td>
1397 <td>invalid, not supported</td>
1401 <td>^/somepath(.*) /otherpath$1</td>
1402 <td>/otherpath/pathinfo</td>
1406 <td>^/somepath(.*) /otherpath$1 [R]</td>
1407 <td>http://thishost/otherpath/pathinfo via external redirection</td>
1411 <td>^/somepath(.*) /otherpath$1 [P]</td>
1412 <td>doesn't make sense, not supported</td>
1416 <td>^/somepath(.*) http://thishost/otherpath$1</td>
1417 <td>/otherpath/pathinfo</td>
1421 <td>^/somepath(.*) http://thishost/otherpath$1 [R]</td>
1422 <td>http://thishost/otherpath/pathinfo via external redirection</td>
1426 <td>^/somepath(.*) http://thishost/otherpath$1 [P]</td>
1427 <td>doesn't make sense, not supported</td>
1431 <td>^/somepath(.*) http://otherhost/otherpath$1</td>
1432 <td>http://otherhost/otherpath/pathinfo via external redirection</td>
1436 <td>^/somepath(.*) http://otherhost/otherpath$1 [R]</td>
1437 <td>http://otherhost/otherpath/pathinfo via external redirection (the [R] flag is redundant)</td>
1441 <td>^/somepath(.*) http://otherhost/otherpath$1 [P]</td>
1442 <td>http://otherhost/otherpath/pathinfo via internal proxy</td>
1446 <p><strong>Inside per-directory configuration for
1447 <code>/somepath</code><br />
1448 (<code>/physical/path/to/somepath/.htaccess</code>, with
1449 <code>RewriteBase /somepath</code>)<br />
1450 for request ``<code>GET
1451 /somepath/localpath/pathinfo</code>'':</strong><br />
1454 <table border="1" style="zebra">
1458 <th>Resulting Substitution</th>
1462 <td>^localpath(.*) otherpath$1</td>
1463 <td>/somepath/otherpath/pathinfo</td>
1467 <td>^localpath(.*) otherpath$1 [R]</td>
1468 <td>http://thishost/somepath/otherpath/pathinfo via external
1473 <td>^localpath(.*) otherpath$1 [P]</td>
1474 <td>doesn't make sense, not supported</td>
1478 <td>^localpath(.*) /otherpath$1</td>
1479 <td>/otherpath/pathinfo</td>
1483 <td>^localpath(.*) /otherpath$1 [R]</td>
1484 <td>http://thishost/otherpath/pathinfo via external redirection</td>
1488 <td>^localpath(.*) /otherpath$1 [P]</td>
1489 <td>doesn't make sense, not supported</td>
1493 <td>^localpath(.*) http://thishost/otherpath$1</td>
1494 <td>/otherpath/pathinfo</td>
1498 <td>^localpath(.*) http://thishost/otherpath$1 [R]</td>
1499 <td>http://thishost/otherpath/pathinfo via external redirection</td>
1503 <td>^localpath(.*) http://thishost/otherpath$1 [P]</td>
1504 <td>doesn't make sense, not supported</td>
1508 <td>^localpath(.*) http://otherhost/otherpath$1</td>
1509 <td>http://otherhost/otherpath/pathinfo via external redirection</td>
1513 <td>^localpath(.*) http://otherhost/otherpath$1 [R]</td>
1514 <td>http://otherhost/otherpath/pathinfo via external redirection (the [R] flag is redundant)</td>
1518 <td>^localpath(.*) http://otherhost/otherpath$1 [P]</td>
1519 <td>http://otherhost/otherpath/pathinfo via internal proxy</td>
1525 </directivesynopsis>