Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

apache rewriterule url-encodes semicolons when it should not

26 views
Skip to first unread message

Alois Treindl

unread,
Jan 6, 2003, 1:25:04 PM1/6/03
to
I have a problem with Apache/1.3.17
and mod_rewrite

I use RewriteRule to rewrite the domain name part for calls to CGIs.
For example, a URL
http://www.oldname.com/cgi-bin/test.cgi?par1=1&par2=2;par3=3
to be rewritten to
http://www.newname.com/cgi-bin/test.cgi?par1=1&par2=2;par3=3

Apache reencodes however in the http redirection reply the semicolon
into its url-encoded representation %3b, so that the
redirected URL is
http://www.newname.com/cgi-bin/test.cgi?par1=1&par2=2%3bpar3=3

This leads to problems later in test.cgi which uses Perl module CGI:
it interprets now Parameter
par2=2;par3=3

i.e. the function of the semicolon as a parameter separator, equivalent
to ampersand & got lost, because Apache did url-encode it during the
rewrite.

Is there a way to prevent Apache from doing that url-encoding of ; into
%3b ?

the rewrite rule is
RewriteRule ^/(.*) http://%{SERVER_NAME}/$1 [L,R=301]

Alois

dav...@yahoo.com

unread,
Jan 6, 2003, 1:36:56 PM1/6/03
to
In alt.apache.configuration Alois Treindl <my_real_firstname@my_real_lastname.com> wrote:
> Is there a way to prevent Apache from doing that url-encoding of ; into
> %3b ?

Isn't much easier to revert the ";" to "&" ?

Davide

Mads Toftum

unread,
Jan 6, 2003, 4:02:44 PM1/6/03
to
On Mon, 06 Jan 2003 19:25:04 +0100, Alois Treindl
<my_real_firstname@my_real_lastname.com> wrote:
> Is there a way to prevent Apache from doing that url-encoding of ; into
> %3b ?
>
> the rewrite rule is
> RewriteRule ^/(.*) http://%{SERVER_NAME}/$1 [L,R=301]
>
Use the flag NE -

noescape|NE' (no URI escaping of output)
This flag keeps mod_rewrite from applying the usual URI escaping rules
to the result of a rewrite. Ordinarily, special characters (such as '%',
'$', ';', and so on) will be escaped into their hexcode equivalents
('%25', '%24', and '%3B', respectively); this flag prevents this from
being done. This allows percent symbols to appear in the output, as in

RewriteRule /foo/(.*) /bar?arg=P1\%3d$1 [R,NE]

which would turn '/foo/zed' into a safe request for '/bar?arg=P1=zed'.

vh

Mads Toftum
--
`Darn it, who spiked my coffee with water?!' - lwall

Alois Treindl

unread,
Jan 7, 2003, 1:02:53 AM1/7/03
to

If you can tell me the rewrite rule to do that, I would have been happy.
I hoped for that when I wrote the request, as I could not find it out
myself.

Some browsers create these URLs from HTML forms, when the forms are
submitted. It is not under our control which URLs we receive at the server.

Semicolons as a paramater separator seems to be generally accepted now.

After writing this newsgroup message I found that starting from Apache
1.3.20 there is a flag [NE] for RewriteRule, which prevents the
url-econding. NE stands for no-encode.

Our test sever runs only Apache 1.3.17, but our production server runs
a higher version of Apache and I could add this flag in the
configuration, so that the problem is effectivle solved. I can live with
the problem on the test server, as long as the production server is free
of it.

dav...@yahoo.com

unread,
Jan 7, 2003, 3:38:36 AM1/7/03
to
In alt.apache.configuration Alois Treindl <my_real_firstname@my_real_lastname.com> wrote:
> Our test sever runs only Apache 1.3.17, but our production server runs
> a higher version of Apache and I could add this flag in the

Huuuu... I suggest you to upgrade your test environment at least at
the same version of Apache used by your production server, otherwise,
you can't "test" for real.

Davide

0 new messages