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
Description: Defines rules for the rewriting engine
+ Pattern Substitution [flags]
Syntax: RewriteRule
- Pattern Substitution
Context: 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,
@@ -1082,6 +1081,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
@@ -1159,6 +1213,7 @@ cannot use $N
in the substitution string!
${mapname:key|default}
)$
N
(N=0..9), which will be replaced
@@ -1178,20 +1233,23 @@ 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
'
@@ -1474,38 +1532,6 @@ virtual host context, rather than in a <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 db8a08e095..7f880bfc3a 100644
--- a/docs/manual/mod/mod_rewrite.xml
+++ b/docs/manual/mod/mod_rewrite.xml
@@ -1075,11 +1075,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
@@ -1173,6 +1229,7 @@ cannot use $N
in the substitution string!
${mapname:key|default}
)$
N
(N=0..9), which will be replaced
@@ -1192,21 +1249,24 @@ 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
'
@@ -1496,39 +1556,6 @@ module="core">Directory section.
type="section" module="core">Location sections, this
should never be necessary and is unsupported.
-
-
-
- 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