From: Rich Bowen Date: Mon, 22 Aug 2011 17:47:41 +0000 (+0000) Subject: Replaces rather weak example with a better one submitted by Marcus X-Git-Tag: 2.3.15~373 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=840f787b3190e5809de199e2908b879ad3f2902a;p=apache Replaces rather weak example with a better one submitted by Marcus Bointon (bug ID 51669) git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1160345 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/docs/manual/rewrite/flags.html.en b/docs/manual/rewrite/flags.html.en index 6042dd6ae9..e0ec73b7f5 100644 --- a/docs/manual/rewrite/flags.html.en +++ b/docs/manual/rewrite/flags.html.en @@ -89,14 +89,22 @@ Using the B flag, non-alphanumeric characters in backreferences will be escaped. For example, consider the rule:

-RewriteRule ^(/.*)$ /index.php?show=$1 +RewriteRule ^search/(.*)$ /search.php?term=$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.

+

Given a search term of 'x & y/z', a browser will encode it as +'x%20%26%20y%2Fz', making the request 'search/x%20%26%20y%2Fz'. Without the B +flag, this rewrite rule will map to 'search.php?term=x & y/z', which +isn't a valid URL, and so would be encoded as +search.php?term=x%20&y%2Fz=, which is not what was intended.

+ +

With the B flag set on this same rule, the parameters are re-encoded +before being passed on to the output URL, resulting in a correct mapping to +/search.php?term=x%20%26%20y%2Fz.

+ +

Note that you may also need to set AllowEncodedSlashes to On to get this +particular example to work, as httpd does not allow encoded slashes in URLs, and +returns a 404 if it sees one.

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

diff --git a/docs/manual/rewrite/flags.xml b/docs/manual/rewrite/flags.xml index 58c5321cc1..b5438aa1a2 100644 --- a/docs/manual/rewrite/flags.xml +++ b/docs/manual/rewrite/flags.xml @@ -80,14 +80,23 @@ Using the B flag, non-alphanumeric characters in backreferences will be escaped. For example, consider the rule:

-RewriteRule ^(/.*)$ /index.php?show=$1 +RewriteRule ^search/(.*)$ /search.php?term=$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.

+

Given a search term of 'x & y/z', a browser will encode it as +'x%20%26%20y%2Fz', making the request 'search/x%20%26%20y%2Fz'. Without the B +flag, this rewrite rule will map to 'search.php?term=x & y/z', which +isn't a valid URL, and so would be encoded as +search.php?term=x%20&y%2Fz=, which is not what was intended.

+ +

With the B flag set on this same rule, the parameters are re-encoded +before being passed on to the output URL, resulting in a correct mapping to +/search.php?term=x%20%26%20y%2Fz.

+ +

Note that you may also need to set AllowEncodedSlashes to On to get this +particular example to work, as httpd does not allow encoded slashes in URLs, and +returns a 404 if it sees one.

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