From: Rich Bowen Date: Wed, 30 Dec 2009 03:54:10 +0000 (+0000) Subject: Makes each flag a top-level section in this doc, thereby giving it a X-Git-Tag: 2.3.5~40 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cebd6925e1601ef820d03ba51b16d364d4aab2db;p=thirdparty%2Fapache%2Fhttpd.git Makes each flag a top-level section in this doc, thereby giving it a navigation link in the right navigation box. I think that makes this page much more useful, particularly when it becomes the primary resource for rewriterule flags and their use. Also adds some detail on several of the flags. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@894539 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/docs/manual/rewrite/flags.html.en b/docs/manual/rewrite/flags.html.en index 43342105aab..5e776bb12fc 100644 --- a/docs/manual/rewrite/flags.html.en +++ b/docs/manual/rewrite/flags.html.en @@ -27,7 +27,26 @@ providing detailed explanations and examples.

See also

top
@@ -44,10 +63,6 @@ RewriteRule pattern target [Flag1,Flag2,Flag3] a longer form, such as cookie. Some flags take one or more arguments. Flags are not case sensitive.

-
top
-
-

The flags

-

Each flag (with a few exceptions) has a long and short form. While it is most common to use the short form, it is recommended that you familiarize yourself with the @@ -55,35 +70,93 @@ long form, so that you remember what each flag is supposed to do.

Presented here are each of the available flags, along with an example of how you might use them.

- -

B

+
top
+
+

B (escape backreferences)

The [B] flag instructs RewriteRule to escape non-alphanumeric characters before applying the transformation.

+

Apache has to unescape URLs before mapping them, +so backreferences will be unescaped at the time they are applied. +Using the B flag, non-alphanumeric characters in backreferences +will be escaped. For example, consider the rule:

-

C|chain

+

+RewriteRule ^(/.*)$ /index.php?show=$1 +

+ +

This will map /C++ to +/index.php?show=/C++. But it will also map +/C%2b%2b to /index.php?show=/C++, because +the %2b has been unescaped. With the B flag, it will +instead map to /index.php?show=/C%2b%2b.

+ +

This escaping is particularly necessary in a proxy situation, +when the backend may break if presented with an unescaped URL.

+ +
top
+
+

C|chain

The [C] or [chain] flag indicates that the RewriteRule is chained to the next rule. That is, if the rule matches, then it is processed as usual and control moves on to the next rule. However, if it does not match, then the next rule, and any other rules that are chained together, will be skipped.

- - -

CO|cookie

+
top
+
+

CO|cookie

The [CO], or [cookie] flag, allows you to set a cookie when a particular RewriteRule -matches. The argument consists of three required fields and two optional +matches. The argument consists of three required fields and five optional fields.

-

You must declare a name and value for the cookie to be set, and the -domain for which you wish the cookie to be valid. You may optionally set -the lifetime of the cookie, and the path for which it should be -returned.

-

By default, the lifetime of the cookie is the current browser -session.

-

By default, the path for which the cookie will be valid is "/" - that -is, the entire website.

+ +

The full syntax for the flag, including all attributes, is as +follows:

+ +

+[CO=NAME:VALUE:domain:lifetime:path:secure:httponly] +

+ +

You must declare a name and value for the cookie to be set.

+ +

You may optionally also set the following values:

+ +
+
Domain
+
The domain for which you want the cookie to be valid. This may be a +hostname, such as www.example.com, or it may be a domain, +such as .example.com. It must be at least two parts +separated by a dot. That is, it may not be merely .com or +.net. Cookies of that kind are forbidden by the cookie +security model.
+
The default value for the domain is the current domain.
+ +
Lifetime
+
The time for which the cookie will persist, in minutes.
+
A value of 0 indicates that the cookie will persist only for the +current browser session. This is the default value if none is +specified.
+ +
Path
+
The path, on the current website, for which the cookie is valid, +such as /customers/ or /files/download/.
+
By default, this is set to / - that is, the entire +website.
+ +
Secure
+
If set to secure, true, or 1, +the cookie will only be permitted to be translated via secure (https) +connections.
+ +
httponly
+
If set to HttpOnly, true, or +1, the cookie will have the HttpOnly flag set, +which means that the cookie will be inaccessible to JavaScript code on +browsers that support this feature.
+
+

Several examples are offered here:

@@ -98,20 +171,58 @@ called 'frontdoor' to a value of 'yes'. The cookie is valid for any host in the .apache.org domain. It will be set to expire in 1440 minutes (24 hours) and will be returned for all URIs.

- - -

DPI|discardpathinfo

+
top
+
+

DPI|discardpathinfo

The DPI flag causes the PATH_INFO portion of the rewritten URI to be discarded.

- - -

E|env

+

This flag is available from 2.2.12

+

In per-directory context, the URI each RewriteRule +compares against is the concatenation of the current values of the URI +and PATH_INFO.

+ +

The current URI can be the initial URI as requested by the client, the +result of a previous round of mod_rewrite processing, or the result of +a prior rule in the current round of mod_rewrite processing.

+ +

In contrast, the PATH_INFO that is appended to the URI before each +rule reflects only the value of PATH_INFO before this round of +mod_rewrite processing. As a consequence, if large portions +of the URI are matched and copied into a substitution in multiple +RewriteRule directives, without regard for +which parts of the URI came from the current PATH_INFO, the final +URI may have multiple copies of PATH_INFO appended to it.

+ +

Use this flag on any substitution where the PATH_INFO that resulted +from the previous mapping of this request to the filesystem is not of +interest. This flag permanently forgets the PATH_INFO established +before this round of mod_rewrite processing began. PATH_INFO will +not be recalculated until the current round of mod_rewrite processing +completes. Subsequent rules during this round of processing will see +only the direct result of substitutions, without any PATH_INFO +appended.

+
top
+
+

E|env

With the [E], or [env] flag, you can set the value of an environment variable. Note that some environment variables may be set after the rule is run, thus unsetting what you have set. See the Environment Variables document for more details on how Environment variables work.

+

The syntax for this flag is:

+ +

+[E:VAR=VAL] +

+ +

VAL may contain backreferences ($N or +%N) which will be expanded.

+ +

These environment variables can then be used in a variety of +contexts, including CGI programs, other RewriteRule directives, or +CustomLog directives.

+

The following example sets an evironment variable called 'image' to a value of '1' if the requested URI is an image file. Then, that environment variable is used to exclude those requests from the access @@ -124,9 +235,9 @@ CustomLog logs/access_log combined env=!image

Note that this same effect can be obtained using SetEnvIf. This technique is offered as an example, not as a recommendation.

- - -

F|forbidden

+
top
+
+

F|forbidden

Using the [F] flag causes Apache to return a 403 Forbidden status code to the client. While the same behavior can be accomplished using the Deny directive, this @@ -143,9 +254,9 @@ RewriteRule \.exe - [F] that the requested URI is not modified. There's no reason to rewrite to another URI, if you're going to forbid the request.

- - -

G|gone

+
top
+
+

G|gone

The [G] flag forces Apache to return a 410 Gone status with the response. This indicates that a resource used to be available, but is no longer available.

@@ -156,9 +267,9 @@ rewrite target when using the [G] flag:

RewriteRule oldproduct - [G,NC]

- - -

H|handler

+
top
+
+

H|handler

Forces the resulting request to be handled with the specified handler. For example, one might use this to force all files without a file extension to be parsed by the php handler:

@@ -186,9 +297,9 @@ match any request that starts with /source/ followed by 1 or n characters followed by .phps literally. The backreference $1 referrers to the captured match within parenthesis of the regular expression.

- - -

L|last

+
top
+
+

L|last

The [L] flag causes mod_rewrite to stop processing the rule set. In most contexts, this means that if the rule matches, no further rules will be processed.

@@ -221,9 +332,9 @@ is already for index.php, the N|next +
top
+
+

N|next

The [N] flag causes the ruleset to start over again from the top. Use with extreme caution, as it may result in loop. @@ -244,9 +355,9 @@ pattern still matches (i.e., while the URI still contains an A), perform this substitution (i.e., replace the A with a B).

- - -

NC|nocase

+
top
+
+

NC|nocase

Use of the [NC] flag causes the RewriteRule to be matched in a case-insensitive manner. That is, it doesn't care whether letters appear as upper-case or lower-case in the matched URI.

@@ -259,9 +370,9 @@ example.

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

- - -

NE|noescape

+
top
+
+

NE|noescape

By default, special characters, such as & and ?, for example, will be converted to their hexcode equivalent. Using the [NE] flag prevents that from happening. @@ -278,9 +389,9 @@ being converted to its hexcode equivalent, %23, which will then result in a 404 Not Found error condition.

- - -

NS|nosubreq

+
top
+
+

NS|nosubreq

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 @@ -291,9 +402,9 @@ 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

+
top
+
+

P|proxy

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 @@ -307,9 +418,9 @@ RewriteRule (.*)\.(jpg|gif|png) http://images.example.com$1.$2 [P] pushed through the proxy, and any following rules will not be considered.

- - -

PT|passthrough

+
top
+
+

PT|passthrough

The target (or substitution string) in a RewriteRule is assumed to be a @@ -338,9 +449,9 @@ 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

+
top
+
+

QSA|qsappend

When the replacement URI contains a query string, the default behavior of RewriteRule is to discard @@ -360,9 +471,9 @@ flag, that same request will be mapped to /page.php?page=123 - that is, the existing query string will be discarded.

- - -

QSD|qsdiscard

+
top
+
+

QSD|qsdiscard

When the requested URI contains a query string, and the target URI does not, the default behavior of RewriteRule is to copy that query @@ -381,9 +492,9 @@ replaced with the query string in the RewriteRule target URI.

- - -

R|redirect

+
top
+
+

R|redirect

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 @@ -405,9 +516,9 @@ on to the next rule in the ruleset, which can often result in 'Invalid URI in request' warnings.

- - -

S|skip

+
top
+
+

S|skip

The [S] flag is used to skip rules that you don't want to run. This can be thought of as a goto statement in your rewrite ruleset. In the following example, we only want to run the RewriteRule if the requested URI @@ -430,9 +541,9 @@ following it. Thus, if you want to make a RewriteCond apply to several RewriteRules, one possible technique is to negate those conditions and use a [Skip] flag.

- - -

T|type

+
top
+
+

T|type

Sets the MIME type with which the resulting response will be sent. This has the same effect as the AddType directive.

@@ -458,8 +569,6 @@ using <FilesMat instead. Always consider the alternate solutions to a problem before resorting to rewrite, which will invariably be a less efficient solution than the alternatives.

- -

Available Languages:  en  | diff --git a/docs/manual/rewrite/flags.xml b/docs/manual/rewrite/flags.xml index 98e01939601..e1c904f016b 100644 --- a/docs/manual/rewrite/flags.xml +++ b/docs/manual/rewrite/flags.xml @@ -47,10 +47,6 @@ RewriteRule pattern target [Flag1,Flag2,Flag3] a longer form, such as cookie. Some flags take one or more arguments. Flags are not case sensitive.

- - -
The flags -

Each flag (with a few exceptions) has a long and short form. While it is most common to use the short form, it is recommended that you familiarize yourself with the @@ -58,12 +54,32 @@ long form, so that you remember what each flag is supposed to do.

Presented here are each of the available flags, along with an example of how you might use them.

+
-
B +
B (escape backreferences)

The [B] flag instructs RewriteRule to escape non-alphanumeric characters before applying the transformation.

+ +

Apache has to unescape URLs before mapping them, +so backreferences will be unescaped at the time they are applied. +Using the B flag, non-alphanumeric characters in backreferences +will be escaped. For example, consider the rule:

+ + +RewriteRule ^(/.*)$ /index.php?show=$1 + + +

This will map /C++ to +/index.php?show=/C++. But it will also map +/C%2b%2b to /index.php?show=/C++, because +the %2b has been unescaped. With the B flag, it will +instead map to /index.php?show=/C%2b%2b.

+ +

This escaping is particularly necessary in a proxy situation, +when the backend may break if presented with an unescaped URL.

+
C|chain @@ -79,16 +95,54 @@ skipped.

CO|cookie

The [CO], or [cookie] flag, allows you to set a cookie when a particular RewriteRule -matches. The argument consists of three required fields and two optional +matches. The argument consists of three required fields and five optional fields.

-

You must declare a name and value for the cookie to be set, and the -domain for which you wish the cookie to be valid. You may optionally set -the lifetime of the cookie, and the path for which it should be -returned.

-

By default, the lifetime of the cookie is the current browser -session.

-

By default, the path for which the cookie will be valid is "/" - that -is, the entire website.

+ +

The full syntax for the flag, including all attributes, is as +follows:

+ + +[CO=NAME:VALUE:domain:lifetime:path:secure:httponly] + + +

You must declare a name and value for the cookie to be set.

+ +

You may optionally also set the following values:

+ +
+
Domain
+
The domain for which you want the cookie to be valid. This may be a +hostname, such as www.example.com, or it may be a domain, +such as .example.com. It must be at least two parts +separated by a dot. That is, it may not be merely .com or +.net. Cookies of that kind are forbidden by the cookie +security model.
+
The default value for the domain is the current domain.
+ +
Lifetime
+
The time for which the cookie will persist, in minutes.
+
A value of 0 indicates that the cookie will persist only for the +current browser session. This is the default value if none is +specified.
+ +
Path
+
The path, on the current website, for which the cookie is valid, +such as /customers/ or /files/download/.
+
By default, this is set to / - that is, the entire +website.
+ +
Secure
+
If set to secure, true, or 1, +the cookie will only be permitted to be translated via secure (https) +connections.
+ +
httponly
+
If set to HttpOnly, true, or +1, the cookie will have the HttpOnly flag set, +which means that the cookie will be inaccessible to JavaScript code on +browsers that support this feature.
+
+

Several examples are offered here:

@@ -108,6 +162,31 @@ minutes (24 hours) and will be returned for all URIs.

DPI|discardpathinfo

The DPI flag causes the PATH_INFO portion of the rewritten URI to be discarded.

+

This flag is available from 2.2.12

+

In per-directory context, the URI each RewriteRule +compares against is the concatenation of the current values of the URI +and PATH_INFO.

+ +

The current URI can be the initial URI as requested by the client, the +result of a previous round of mod_rewrite processing, or the result of +a prior rule in the current round of mod_rewrite processing.

+ +

In contrast, the PATH_INFO that is appended to the URI before each +rule reflects only the value of PATH_INFO before this round of +mod_rewrite processing. As a consequence, if large portions +of the URI are matched and copied into a substitution in multiple +RewriteRule directives, without regard for +which parts of the URI came from the current PATH_INFO, the final +URI may have multiple copies of PATH_INFO appended to it.

+ +

Use this flag on any substitution where the PATH_INFO that resulted +from the previous mapping of this request to the filesystem is not of +interest. This flag permanently forgets the PATH_INFO established +before this round of mod_rewrite processing began. PATH_INFO will +not be recalculated until the current round of mod_rewrite processing +completes. Subsequent rules during this round of processing will see +only the direct result of substitutions, without any PATH_INFO +appended.

E|env @@ -117,6 +196,19 @@ is run, thus unsetting what you have set. See the Environment Variables document for more details on how Environment variables work.

+

The syntax for this flag is:

+ + +[E:VAR=VAL] + + +

VAL may contain backreferences ($N or +%N) which will be expanded.

+ +

These environment variables can then be used in a variety of +contexts, including CGI programs, other RewriteRule directives, or +CustomLog directives.

+

The following example sets an evironment variable called 'image' to a value of '1' if the requested URI is an image file. Then, that environment variable is used to exclude those requests from the access @@ -478,6 +570,5 @@ solutions to a problem before resorting to rewrite, which will invariably be a less efficient solution than the alternatives.

-