-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Joe,

On 1/29/16 9:34 AM, Joe Aldrich wrote:
> I am using Tomcat 8.0.28 on Windows 10 and am having a problem with
> the Rewrite Value. I must include the escaped form of an ampersand
> '%26' in the output URL.
> 
> My rewrite.config has the following:
> 
> RewriteCond %{QUERY_STRING} ^(.*&)?SCID=8(&.*)?$ RewriteRule
> ^/(product|specs|avail-options|avail-category)\.php$
> /Product.action?select=Model+4+\%26+4C [R=301,L,NE]
> 
> I am escaping the percent sign with a backslash, and I have tried
> using the NE flag. However, Tomcat always is treating the percent
> symbol as a back reference to the above RewriteCond. If I don't
> have a second capture group, then I get a 500 error from a
> NullPointerException.

Can you please post the stack trace from that?

> I was working with the documentation on this page:
> 
> http://tomcat.apache.org/tomcat-8.0-doc/rewrite.html
> 
> The desired output URL would be:
> 
> http://www.domain.com/Product.html?select=Model+4+%26+4C

Presumably, if you don't escape it at all, you get:

http://www.domain.com/Product.html?select=Model+4+%2526+4C

?

> In the example given for the NE flag on the page reference above,
> the percent sign is escaped by a backslash to prevent it from being
> treated as a back-reference. This is not working for me. Instead I
> get:
> 
> http://www.domain.com/Product.action?select=Model+4+\null6+4C
> 
> Where the "null" is due to an empty second back-reference.  I
> believe this is a bug in that it is not escaping the percent sign
> (making it impossible to create the %26 in the redirect URL). Or am
> I misunderstanding something here?
> 
> As a side question, shouldn't an empty back-reference be blank
> instead of adding 'null' to the URL?

I agree that the "null" is incorrect. That is almost certainly a bug.

[NE] should be preventing escaping of the resulting URL, but that
might break if you had user-specified input being re-written, but then
not escaped.

I'm not entirely sure if backslash-escaping is expected to work for
back-references. It's certainly a reasonable expectation, especially
if that's the way that mod_rewrite works (and I don't know if that's
the case). The "escaping" section is only mentioned in the "regular
expressions" section, and not in the "backreferences" section, which
is why I think there may be some room for alternative interpretations,
here.

I'm curious if \$25 works (as opposed to \%25), and this is merely an
oversight for one type of backreference. Can you confirm whether \$25
works as you expect (i.e. resulting in a URL containing a literal $25)?

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlary+YACgkQ9CaO5/Lv0PAjOACgrxb5md+QtRwzENQCOWtonQft
K70An3MWvKlh2nFgEL/mhjZK+RGIHB2y
=0g9b
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to