From: Joshua Slive The The Pattern will initially be matched against the part of the
+ URL after the hostname and port, and before the query string. If you wish
+ to match against the hostname, port, or query string, use a
+ Some hints on the syntax of regular
expressions: For more information about regular expressions, have a look at the
- perl regular expression manpage ("perldoc
+ perl regular expression manpage ("perldoc
perlre"). If you are interested in more detailed
information about regular expressions and their variants
(POSIX regex etc.) the following book is dedicated to this topic: The substitution of a
- rewrite rule is the string which is substituted for (or
- replaces) the original URL which Pattern
- matched. In addition to plain text, it can include The Substitution of a
+ rewrite rule is the string that replaces the original URL-path that
+ was matched by Pattern. The Substitution may
+ be a: In addition to plain text, the Substition string can include Back-references are identifiers of the form
There is a special substitution string named
- ' By default, the query string is passed through unchanged. You
+ can, however, create URLs in the substitution string containing
+ a query string part. Simply use a question mark inside the
+ substitution string to indicate that the following text should
+ be re-injected into the query string. When you want to erase an
+ existing query string, end the substitution string with just a
+ question mark. To combine new and old query strings, use the
+ Additionally you can set special flags for Substitution by
+ Additionally you can set special actions to be performed by
appending instead of
. Seems much more readable to me.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x@562107 13f79535-47bb-0310-9956-ffa450edef68
---
diff --git a/docs/manual/mod/mod_rewrite.html.en b/docs/manual/mod/mod_rewrite.html.en
index 20cf415e86d..c598d72aa71 100644
--- a/docs/manual/mod/mod_rewrite.html.en
+++ b/docs/manual/mod/mod_rewrite.html.en
@@ -1042,12 +1042,11 @@ later
Description: Defines rules for the rewriting engine
+ Pattern Substitution [flags]
Syntax: RewriteRule
- Pattern SubstitutionContext: server config, virtual host, directory, .htaccess Override: FileInfo Status: Extension
-Module: mod_rewrite Compatibility: The cookie-flag is available in Apache 2.0.40 and later. RewriteRule directive is the real
rewriting workhorse. The directive can occur more than once,
@@ -1062,6 +1061,17 @@ later
subsequent patterns are applied to the output of the last matched
RewriteRule.What is matched?
+ RewriteCond with the
+ %{HTTP_HOST}, %{SERVER_PORT}, or
+ %{QUERY_STRING} variables respectively.$N in the substitution string!
-
+
+
+
+ DocumentRoot-relative path to the
+ resource to be served. Note that mod_rewrite
+ tries to guess whether you have specified a file-system path
+ or a URL-path by checking to see if the first segement of the
+ path exists at the root of the file-system. For example, if
+ you specify a Substitution string of
+ /www/file.html, then this will be treated as a
+ URL-path unless a directory named www
+ exists at the root or your file-system, in which case it will
+ be treated as a file-system path. If you wish other
+ URL-mapping directives (such as Alias) to be applied to the
+ resulting URL-path, use the [PT] flag as
+ described below.mod_rewrite checks to see whether the
+ hostname matches the current host. If it does, the scheme and
+ hostname are stripped out and the resulting path is treated as
+ a URL-path. Otherwise, an external redirect is performed for
+ the given URL. To force an external redirect back to the
+ current host, see the [R] flag below.- (dash)
+
$N) to the RewriteRule
@@ -1139,6 +1193,7 @@ cannot use $N in the substitution string!
${mapname:key|default})$N
(N=0..9), which will be replaced
@@ -1158,24 +1213,27 @@ cannot use $N in the substitution string!
or it is explicitly terminated by a
L flag.-' which means: NO
- substitution! This is useful in providing
- rewriting rules which only match
- URLs but do not substitute anything for them. It is commonly used
- in conjunction with the C (chain) flag, in order
- to apply more than one pattern before substitution occurs.Modifying the Query String
+ [QSA] flag.[flags]
as the third argument to the RewriteRule
- directive. Flags is a comma-separated list of any of the
- following flags:
chain|C'
- (chained with next rule)chain|C'
+ (chained with next rule)$N in the substitution string!
rules are skipped. For instance, it can be used 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!)..www'' part should not occur!).
- cookie|CO=NAME:VAL:domain[:lifetime[:path]]'
- (set cookie)cookie|CO=NAME:VAL:domain[:lifetime[:path]]'
+ (set cookie)env|E=VAR:VAL'
- (set environment variable)env|E=VAR:VAL'
+ (set environment variable)$N and
@@ -1210,67 +1268,69 @@ cannot use $N in the substitution string!
var="VAR"-->) or CGI ($ENV{'VAR'}).
You can also dereference the variable in a later RewriteCond pattern, using
%{ENV:VAR}. Use this to strip
- information from URLs, while maintaining a record of that information.forbidden|F' (force URL
- to be forbidden)forbidden|F' (force URL
+ to be forbidden)gone|G' (force URL to be
- gone)gone|G' (force URL to be
+ gone)handler|H=Content-handler'
- (force Content handler)handler|H=Content-handler'
+ (force Content handler)mod_alias directive
ScriptAlias,
which internally forces all files
inside the mapped directory to have a handler of
- ``cgi-script''.last|L'
- (last rule)last command or the break command
- in C. Use this flag to prevent the currently
- rewritten URL from being rewritten further by following
- rules. For example, use it to rewrite the root-path URL
- ('/') to a real one, e.g.,
- '/e/www/'.next|N'
- (next round)cgi-script''.
+
+ last|L'
+ (last rule)last command or the
+ break command in C. Use this flag to prevent the
+ currently rewritten URL from being rewritten further by
+ following rules. Remember, however, that if the
+ RewriteRule generates an internal
+ redirect (which frequently occurs when rewriting in a
+ per-directory context), this will reinject the request and
+ will cause processing to be repeated starting from the first
+ RewriteRule.next|N'
+ (next round)next command or
the continue command in C. Use
this flag to restart the rewriting process -
- to immediately go to the top of the loop.nocase|NC'
- (no case)nocase|NC'
+ (no case)noescape|NE'
- (no URI escaping of
- output)noescape|NE'
+ (no URI escaping of
+ output)$N in the substitution string!
which would turn '/foo/zed' into a safe
request for '/bar?arg=P1=zed'.
- nosubreq|NS'
- (not for internal
- sub-requests)nosubreq|NS'
+ (not for internal
+ sub-requests)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 Apache when mod_include tries to find out
@@ -1297,17 +1357,17 @@ cannot use $N in the substitution string!
(index.xxx files). On sub-requests it is not
always useful, and can even cause errors, if
the complete set of rules are applied. Use this flag to
- exclude some rules.
- To decide whether or not to use this rule: if you
+ exclude some rules.
To decide whether or not to use this rule: if you prefix URLs with CGI-scripts, to force them to be processed by the CGI-script, it's likely that you will run into problems (or significant overhead) on - sub-requests. In these cases, use this flag. -
proxy|P' (force
- proxy)proxy|P' (force
+ proxy)$N in the substitution string!
Note: mod_proxy must be enabled in order
to use this flag.
passthrough|PT'
- (pass through to next
- handler)passthrough|PT'
+ (pass through to next
+ handler)uri field of the internal
request_rec structure to the value of the
@@ -1362,54 +1422,58 @@ cannot use $N in the substitution string!
The PT flag implies the L flag:
rewriting will be stopped in order to pass the request to
the next phase of processing.
qsappend|QSA'
- (query string
- append)qsappend|QSA'
+ (query string
+ append)redirect|R
- [=code]' (force redirect)redirect|R
+ [=code]' (force redirect)Prefix Substitution with
http://thishost[:thisport]/ (which makes the
new URL a URI) to force a external redirection. If no
code is given, a HTTP response of 302 (MOVED
- TEMPORARILY) will be returned. If you want to use other response
- codes in the range 300-400, simply specify the appropriate number
- or use one of the following symbolic names:
- temp (default), permanent,
- seeother. Use this for rules to
- canonicalize the URL and return it to the client - to
- translate ``/~'' into
- ``/u/'', or to always append a slash to
- /u/user, etc.
- Note: When you use this flag, make
- sure that the substitution field is a valid URL! Otherwise,
- you will be redirecting to an invalid location. Remember
- that this flag on its own will only prepend
- http://thishost[:thisport]/ to the URL, and rewriting
- will continue. Usually, you will want to stop rewriting at this point,
- and redirect immediately. To stop rewriting, you should add
- the 'L' flag.
-
skip|S=num'
- (skip next rule(s))temp
+ (default), permanent,
+ seeother. Use this for rules to canonicalize
+ the URL and return it to the client - to translate
+ ``/~'' into ``/u/'', or to always
+ append a slash to /u/user, etc.http://thishost[:thisport]/ to the URL, and
+ rewriting will continue. Usually, you will want to stop
+ rewriting at this point, and redirect immediately. To stop
+ rewriting, you should add the 'L' flag.
+ While this is typically used for redirects, any valid status
+ code can be given here. If the status code is outside the redirect
+ range (300-399), then the Substitution string is dropped
+ and rewriting is stopped as if the L flag was
+ used.
skip|S=num'
+ (skip next rule(s))skip=N, where N is the number of rules in the
else-clause. (This is not the same as the
- 'chain|C' flag!)type|T=MIME-type'
- (force MIME type)type|T=MIME-type'
+ (force MIME type)$N in the substitution string!
RewriteRule ^(.+\.php)s$ $1 [T=application/x-httpd-php-source]
<Location> sections, this
should never be necessary and is unsupported.
-
- When you prefix a substitution field with
- http://thishost[:thisport], mod_rewrite will automatically strip that
- out. This auto-reduction on URLs with an implicit
- external redirect is most useful in
- combination with a mapping-function which generates the
- hostname part.
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.
The Pattern will initially be matched against the part of the
- URL after the hostname and port, and before the query string. If you wish
- to match against the hostname, port, or query string, use a
- RewriteCond with the
- %{HTTP_HOST}, %{SERVER_PORT}, or
- %{QUERY_STRING} variables respectively.
You can, however, create URLs in the substitution string containing a
- query string part. Simply use a question mark inside the substitution
- string, to indicate that the following text should be re-injected into the
- query string. When you want to erase an existing query string,
- end the substitution string with just a question mark. To
- combine new and old query strings, use the
- [QSA] flag.
Here are all possible substitution combinations and their
diff --git a/docs/manual/mod/mod_rewrite.xml b/docs/manual/mod/mod_rewrite.xml
index 017b9237a0b..d818c8935b6 100644
--- a/docs/manual/mod/mod_rewrite.xml
+++ b/docs/manual/mod/mod_rewrite.xml
@@ -1055,11 +1055,10 @@ RewriteRule ^/$ /homepage.std.html [L]
The The Pattern will initially be matched against the part of the
+ URL after the hostname and port, and before the query string. If you wish
+ to match against the hostname, port, or query string, use a
+ Some hints on the syntax of For more information about regular expressions, have a look at the
perl regular expression manpage ("perldoc
+ href="http://www.perldoc.com/perlre.html">perldoc
perlre"). If you are interested in more detailed
information about regular expressions and their variants
(POSIX regex etc.) the following book is dedicated to this topic: The substitution of a
- rewrite rule is the string which is substituted for (or
- replaces) the original URL which Pattern
- matched. In addition to plain text, it can include The Substitution of a
+ rewrite rule is the string that replaces the original URL-path that
+ was matched by Pattern. The Substitution may
+ be a: In addition to plain text, the Substition string can include Back-references are identifiers of the form
There is a special substitution string named
- ' By default, the query string is passed through unchanged. You
+ can, however, create URLs in the substitution string containing
+ a query string part. Simply use a question mark inside the
+ substitution string to indicate that the following text should
+ be re-injected into the query string. When you want to erase an
+ existing query string, end the substitution string with just a
+ question mark. To combine new and old query strings, use the
+ Additionally you can set special flags for Substitution by
+ id="rewriteflags">actions to be performed by
appending %{HTTP_HOST}, %{SERVER_PORT}, or
+ %{QUERY_STRING} variables respectively.$N in the substitution string!
-
+
+
+
+ /www/file.html, then this will be treated as a
+ URL-path unless a directory named www
+ exists at the root or your file-system, in which case it will
+ be treated as a file-system path. If you wish other
+ URL-mapping directives (such as [PT] flag as
+ described below.[R] flag below.- (dash)
+
$N) to the RewriteRule
@@ -1153,6 +1209,7 @@ cannot use $N in the substitution string!
${mapname:key|default})$N
(N=0..9), which will be replaced
@@ -1172,25 +1229,28 @@ cannot use $N in the substitution string!
or it is explicitly terminated by a
L flag.-' which means: NO
- substitution! This is useful in providing
- rewriting rules which only match
- URLs but do not substitute anything for them. It is commonly used
- in conjunction with the C (chain) flag, in order
- to apply more than one pattern before substitution occurs.[QSA] flag.[flags]
as the third argument to the RewriteRule
- directive. Flags is a comma-separated list of any of the
- following flags:
chain|C'
- (chained with next rule)chain|C'
+ (chained with next rule)$N in the substitution string!
rules are skipped. For instance, it can be used 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!)..www'' part should not occur!).
- cookie|CO=NAME:VAL:domain[:lifetime[:path]]'
- (set cookie)cookie|CO=NAME:VAL:domain[:lifetime[:path]]'
+ (set cookie)env|E=VAR:VAL'
- (set environment variable)env|E=VAR:VAL'
+ (set environment variable)$N and
@@ -1225,67 +1285,69 @@ cannot use $N in the substitution string!
var="VAR"-->) or CGI ($ENV{'VAR'}).
You can also dereference the variable in a later RewriteCond pattern, using
%{ENV:VAR}. Use this to strip
- information from URLs, while maintaining a record of that information.forbidden|F' (force URL
- to be forbidden)forbidden|F' (force URL
+ to be forbidden)gone|G' (force URL to be
- gone)gone|G' (force URL to be
+ gone)handler|H=Content-handler'
- (force Content handler)handler|H=Content-handler'
+ (force Content handler)cgi-script''.last|L'
- (last rule)last command or the break command
- in C. Use this flag to prevent the currently
- rewritten URL from being rewritten further by following
- rules. For example, use it to rewrite the root-path URL
- ('/') to a real one, e.g.,
- '/e/www/'.next|N'
- (next round)cgi-script''.
+
+ last|L'
+ (last rule)last command or the
+ break command in C. Use this flag to prevent the
+ currently rewritten URL from being rewritten further by
+ following rules. Remember, however, that if the
+ next|N'
+ (next round)next command or
the continue command in C. Use
this flag to restart the rewriting process -
- to immediately go to the top of the loop.nocase|NC'
- (no case)nocase|NC'
+ (no case)noescape|NE'
- (no URI escaping of
- output)noescape|NE'
+ (no URI escaping of
+ output)$N in the substitution string!
which would turn '/foo/zed' into a safe
request for '/bar?arg=P1=zed'.
- nosubreq|NS'
- (not for internal
- sub-requests)nosubreq|NS'
+ (not for internal
+ sub-requests)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 Apache when $N in the substitution string!
(index.xxx files). On sub-requests it is not
always useful, and can even cause errors, if
the complete set of rules are applied. Use this flag to
- exclude some rules.
- To decide whether or not to use this rule: if you
+ exclude some rules.
To decide whether or not to use this rule: if you prefix URLs with CGI-scripts, to force them to be processed by the CGI-script, it's likely that you will run into problems (or significant overhead) on - sub-requests. In these cases, use this flag. -
proxy|P' (force
- proxy)proxy|P' (force
+ proxy)Note:
passthrough|PT'
- (pass through to next
- handler)passthrough|PT'
+ (pass through to next
+ handler)uri field of the internal
request_rec structure to the value of the
@@ -1379,55 +1441,59 @@ cannot use $N in the substitution string!
The PT flag implies the L flag:
rewriting will be stopped in order to pass the request to
the next phase of processing.
qsappend|QSA'
- (query string
- append)qsappend|QSA'
+ (query string
+ append)redirect|R
- [=code]' (force redirect)redirect|R
+ [=code]' (force redirect)Prefix Substitution with
http://thishost[:thisport]/ (which makes the
new URL a URI) to force a external redirection. If no
code is given, a HTTP response of 302 (MOVED
- TEMPORARILY) will be returned. If you want to use other response
- codes in the range 300-400, simply specify the appropriate number
- or use one of the following symbolic names:
- temp (default), permanent,
- seeother. Use this for rules to
- canonicalize the URL and return it to the client - to
- translate ``/~'' into
- ``/u/'', or to always append a slash to
- /u/user, etc.
- Note: When you use this flag, make
- sure that the substitution field is a valid URL! Otherwise,
- you will be redirecting to an invalid location. Remember
- that this flag on its own will only prepend
- http://thishost[:thisport]/ to the URL, and rewriting
- will continue. Usually, you will want to stop rewriting at this point,
- and redirect immediately. To stop rewriting, you should add
- the 'L' flag.
-
skip|S=num'
- (skip next rule(s))temp
+ (default), permanent,
+ seeother. Use this for rules to canonicalize
+ the URL and return it to the client - to translate
+ ``/~'' into ``/u/'', or to always
+ append a slash to /u/user, etc.http://thishost[:thisport]/ to the URL, and
+ rewriting will continue. Usually, you will want to stop
+ rewriting at this point, and redirect immediately. To stop
+ rewriting, you should add the 'L' flag.
+ While this is typically used for redirects, any valid status
+ code can be given here. If the status code is outside the redirect
+ range (300-399), then the Substitution string is dropped
+ and rewriting is stopped as if the L flag was
+ used.
skip|S=num'
+ (skip next rule(s))skip=N, where N is the number of rules in the
else-clause. (This is not the same as the
- 'chain|C' flag!)type|T=MIME-type'
- (force MIME type)type|T=MIME-type'
+ (force MIME type)$N in the substitution string!
- When you prefix a substitution field with
- http://thishost[:thisport],
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.
The Pattern will initially be matched against the part of the
- URL after the hostname and port, and before the query string. If you wish
- to match against the hostname, port, or query string, use a
- %{HTTP_HOST}, %{SERVER_PORT}, or
- %{QUERY_STRING} variables respectively.
You can, however, create URLs in the substitution string containing a
- query string part. Simply use a question mark inside the substitution
- string, to indicate that the following text should be re-injected into the
- query string. When you want to erase an existing query string,
- end the substitution string with just a question mark. To
- combine new and old query strings, use the
- [QSA] flag.
Here are all possible substitution combinations and their