Bug 27985 - mod_rewrite adds a per-dir-prefix to proxy requests, all requests now return error 400
Summary: mod_rewrite adds a per-dir-prefix to proxy requests, all requests now return ...
Status: CLOSED FIXED
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mod_rewrite (show other bugs)
Version: 2.0.50
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-03-26 14:50 UTC by Sven Koch
Modified: 2004-11-16 19:05 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sven Koch 2004-03-26 14:50:18 UTC
When using Apache 2.0.49 mod_rewrite with rewrite-maps on proxied requests,
apache applies a false per-dir prefix and garbles the url.

Apache 2.0.48 was working as expected.


I have the following statements in my httpd.conf (simplified):

RewriteMap      proxy-map       prg:/usr/local/bin/proxy-map
RewriteMap      local-map       prg:/usr/local/bin/proxy-local-map

<Proxy *>
        RewriteEngine On
        RewriteCond %{SERVER_ADDR} ^127\.0\.0
        RewriteRule ^proxy:http://id/$ http://localhost/cgi-bin/id [R,L]
        RewriteRule ^(.*)$ ${proxy-map:$1|$1}
        RewriteCond %{SERVER_ADDR} ^127\.0\.0
        RewriteRule ^(.*)$ ${local-map:$1|$1}
</Proxy>

The output of RewriteLog on Level 9:

(3) [per-dir */] applying pattern '^proxy:http://id/$' to uri
'proxy:http://www.apache.org/'
(3) [per-dir */] applying pattern '^(.*)$' to uri 'proxy:http://www.apache.org/'
(5) map lookup OK: map=proxy-map key=proxy:http://www.apache.org/ ->
val=proxy:http://www.apache.org/
(2) [per-dir */] rewrite proxy:http://www.apache.org/ ->
proxy:http://www.apache.org/
(3) [per-dir */] add per-dir prefix: proxy:http://www.apache.org/ ->
*/proxy:http://www.apache.org/
(3) [per-dir */] strip per-dir prefix: */proxy:http://www.apache.org/ ->
proxy:http://www.apache.org/
(3) [per-dir */] applying pattern '^(.*)$' to uri 'proxy:http://www.apache.org/'
(4) RewriteCond: input='127.0.0.1' pattern='^127\.0\.0' => matched
(5) map lookup OK: map=local-map key=proxy:http://www.apache.org/ ->
val=proxy:http://www.apache.org/
(2) [per-dir */] rewrite proxy:http://www.apache.org/ ->
proxy:http://www.apache.org/
(3) [per-dir */] add per-dir prefix: proxy:http://www.apache.org/ ->
*/proxy:http://www.apache.org/

Nothing in the error-log, and only the following in the access-log:

127.0.0.1 - - [26/Mar/2004:15:02:58 +0100] "GET http://www.apache.org/ HTTP/1.1"
400 - "-" "Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:1.6) Gecko/20040312" 0 "-"
Comment 1 André Malo 2004-03-27 00:03:58 UTC
Hrm. That is a problem. mod_rewrite now treats the result string
'proxy:http://www.apache.org/' as a relative path, which was a bug fix in 2.0.49
(for some other example, but ...).

Frankly speaking, your rules depend on unsupported API internals, so you cannot
expect that they work forever.

Anyway: Can you try what happens if you just take the rules out of the <Proxy>
container? (That's even the next problem, mod_rewrite was never designed for use
within <Proxy>).
Comment 2 Sven Koch 2004-03-27 00:34:48 UTC
> Frankly speaking, your rules depend on unsupported API internals

I didn't even know that this setup was unsupported ;)

It worked with only minor changes (<Location proxy:*> changed to <Proxy *>) from
a  very old apache 1.3 through 2.0.48 without problems.

I will try your suggestion on monday, when I can reach my test-box again.
Comment 3 Sven Koch 2004-03-29 13:53:12 UTC
I just tried your suggestion of placing the RewriteRules outside of <Proxy>:

The Rules are tested only for local connections, not for connections proxied
through the apache. Thus they are called exactly when I don't need any rewriting.

I'm back to apache 2.0.48 for now.
Comment 4 André Malo 2004-03-29 18:38:18 UTC
Well, thanks. I'm investigating how to fix it somehow.
Comment 5 André Malo 2004-03-29 22:06:57 UTC
I've nailed the problem in 2.1 and proposed it for backport into the 2.0 branch.

If you want to to try it out, here's a patch against 2.0:
<http://cvs.apache.org/~nd/mod_rewrite.c.patch>
Comment 6 Sven Koch 2004-03-31 16:15:15 UTC
Just a small follow-up:

Your patch fixes my problems with 2.0.49, the rewrite/filter rules are working
again.

Thanks a lot.
Comment 7 André Malo 2004-04-01 18:53:15 UTC
Thanks for the feedback :-)
Comment 8 Sven Koch 2004-07-13 10:19:00 UTC
This bug is in 2.0.50 too, and the same patch as for 2.0.49 still fixes it.
Comment 9 André Malo 2004-08-27 07:42:24 UTC
Well, the fix was finally reviewed and will be in 2.0.51.