From: Rich Bowen Date: Tue, 14 Aug 2007 01:32:07 +0000 (+0000) Subject: Complete the various flags. I'd like to see more examples here, and X-Git-Tag: 2.3.0~1610 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0c83d1dd09d3252f0d979501e1ee335a74610d79;p=thirdparty%2Fapache%2Fhttpd.git Complete the various flags. I'd like to see more examples here, and perhaps some of the examples that are given in the main doc can be expanded on somewhat, here, in a rather less confusing manner. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@565602 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/docs/manual/rewrite/flags.html.en b/docs/manual/rewrite/flags.html.en index 3779cee9abc..73bd33ee475 100644 --- a/docs/manual/rewrite/flags.html.en +++ b/docs/manual/rewrite/flags.html.en @@ -223,23 +223,109 @@ being converted to its hexcode equivalent, %23.

NS|nosubreq

-

No internal subrequest flag

+

Use of the [NS] flag prevents the rule from being used on +subrequests. For example, a page which is included using an SSI (Server +Side Include) is a subrequest, and you may want to avoid rewrites +happening on those subrequests.

+ +

+Images, javascript files, or css files, loaded as part of an HTML page, +are not subrequests - the browser requests them as separate HTTP +requests. +

P|proxy

-

Proxy flag

+

Use of the [P] flag causes the request to be handled by +mod_proxy, and handled via a proxy request. For +example, if you wanted all image requests to be handled by a back-end +image server, you might do something like the following:

+ +

+RewriteRule (.*)\.(jpg|gif|png) http://images.example.com$1.$2 [P] +

+ +

Use of the [P] flag implies [L] - that is, the request is immediatly +pushed through the proxy, and any following rules will not be +considered.

+

PT|passthrough

-

Passthrough flag

+ +

+The target (or substitution string) in a RewriteRule is assumed to be a +file path, by default. The use of the [PT] flag causes it to be trated +as a URI instead. That is to say, the +use of the [PT] flag causes the result of the RewriteRule to be passed back through +URL mapping, so that location-based mappings, such as Alias, for example, might have a chance to take +effect. +

+ +

+If, for example, you have an +Alias +for /icons, and have a RewriteRule pointing there, you should +use the [PT] flag to ensure that the +Alias is evaluated. +

+ +

+Alias /icons /usr/local/apache/icons +RewriteRule /pics/(.+)\.jpg /icons/$1.gif [PT] +

+ +

+Omission of the [PT] flag in this case will cause the Alias to be +ignored, resulting in a 'File not found' error being returned. +

+

QSA|qsappend

-

Query String Append flag

+

+When the replacement URI contains a query string, the default behavior +of RewriteRule is to discard +the existing query string, and replace it with the newly generated one. +Using the [QSA] flag causes the query strings to be combined. +

+ +

Consider the following rule:

+ +

+RewriteRule /pages/(.+) /page.php?page=$1 [QSA] +

+ +

With the [QSA] flag, a request for /pages/123?one=two will be +mapped to /page.php?page=123&one=two. Without the [QSA] +flag, that same request will be mapped to +/page.php?page=123 - that is, the existing query string +will be discarded. +

R|redirect

-

Redirect flag

+

+Use of the [R] flag causes a HTTP redirect to be issued to the browser. +If a fully-qualified URL is specified (that is, including +http://servername/) then a redirect will be issued to that +location. Otherwise, the current servername will be used to generate the +URL sent with the redirect. +

+ +

+A status code may be specified, in the range 300-399, with a 302 status +code being used by default if none is specified. +

+ +

+You will almost always want to use [R] in conjunction with [L] (that is, +use [R,L]) because on its own, the [R] flag prepends +http://thishost[:thisport] to the URI, but then passes this +on to the next rule in the ruleset, which can often result in 'Invalid +URI in request' warnings. +

+

S|skip

diff --git a/docs/manual/rewrite/flags.xml b/docs/manual/rewrite/flags.xml index c346b35f18b..437120fbf45 100644 --- a/docs/manual/rewrite/flags.xml +++ b/docs/manual/rewrite/flags.xml @@ -234,23 +234,112 @@ being converted to its hexcode equivalent, %23.
NS|nosubreq -

No internal subrequest flag

+

Use of the [NS] flag prevents the rule from being used on +subrequests. For example, a page which is included using an SSI (Server +Side Include) is a subrequest, and you may want to avoid rewrites +happening on those subrequests.

+ +

+Images, javascript files, or css files, loaded as part of an HTML page, +are not subrequests - the browser requests them as separate HTTP +requests. +

P|proxy -

Proxy flag

+

Use of the [P] flag causes the request to be handled by +mod_proxy, and handled via a proxy request. For +example, if you wanted all image requests to be handled by a back-end +image server, you might do something like the following:

+ + +RewriteRule (.*)\.(jpg|gif|png) http://images.example.com$1.$2 [P] + + +

Use of the [P] flag implies [L] - that is, the request is immediatly +pushed through the proxy, and any following rules will not be +considered.

+
PT|passthrough -

Passthrough flag

+ +

+The target (or substitution string) in a RewriteRule is assumed to be a +file path, by default. The use of the [PT] flag causes it to be trated +as a URI instead. That is to say, the +use of the [PT] flag causes the result of the RewriteRule to be passed back through +URL mapping, so that location-based mappings, such as Alias, for example, might have a chance to take +effect. +

+ +

+If, for example, you have an +Alias +for /icons, and have a RewriteRule pointing there, you should +use the [PT] flag to ensure that the +Alias is evaluated. +

+ + +Alias /icons /usr/local/apache/icons +RewriteRule /pics/(.+)\.jpg /icons/$1.gif [PT] + + +

+Omission of the [PT] flag in this case will cause the Alias to be +ignored, resulting in a 'File not found' error being returned. +

+
QSA|qsappend -

Query String Append flag

+

+When the replacement URI contains a query string, the default behavior +of RewriteRule is to discard +the existing query string, and replace it with the newly generated one. +Using the [QSA] flag causes the query strings to be combined. +

+ +

Consider the following rule:

+ + +RewriteRule /pages/(.+) /page.php?page=$1 [QSA] + + +

With the [QSA] flag, a request for /pages/123?one=two will be +mapped to /page.php?page=123&one=two. Without the [QSA] +flag, that same request will be mapped to +/page.php?page=123 - that is, the existing query string +will be discarded. +

R|redirect -

Redirect flag

+

+Use of the [R] flag causes a HTTP redirect to be issued to the browser. +If a fully-qualified URL is specified (that is, including +http://servername/) then a redirect will be issued to that +location. Otherwise, the current servername will be used to generate the +URL sent with the redirect. +

+ +

+A status code may be specified, in the range 300-399, with a 302 status +code being used by default if none is specified. +

+ +

+You will almost always want to use [R] in conjunction with [L] (that is, +use [R,L]) because on its own, the [R] flag prepends +http://thishost[:thisport] to the URI, but then passes this +on to the next rule in the ruleset, which can often result in 'Invalid +URI in request' warnings. +

+
S|skip