Bug 7492

Summary: Rewritemap mismerges paths (c:/ not recognized as rooted)
Product: Apache httpd-1.3 Reporter: Yuriy Ryabikov <yuriy.ryabikov>
Component: mod_rewriteAssignee: Apache HTTPD Bugs Mailing List <bugs>
Status: CLOSED FIXED    
Severity: major CC: bugzilla, jeb
Priority: P3    
Version: 1.3.27   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: httpd.conf
rewrite.log
perl CGI

Description Yuriy Ryabikov 2002-03-26 17:55:12 UTC
-begin----httpd.conf-----

<Directory "C:/Program Files/Apache Group/Apache/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride All
RewriteEngine on
RewriteRule ^(.*)$ $1/%{REMOTE_ADDR}
RewriteRule ^(.*)$ ${AntiLeech:$1|/leech2.html}
    Order allow,deny
    Allow from all
</Directory>

<VirtualHost *:87>
     ServerAdmin webmaster@localhost
     DocumentRoot "C:/Program Files/Apache Group/Apache/htdocs"
     ServerName localhost

RewriteEngine on
RewriteMap AntiLeech prg:C:/PROGRA~1/APACHE~1/APACHE/HTDOCS/1.pl
RewriteLog "C:/PROGRA~1/APACHE~1/APACHE/HTDOCS/rewrite.log"
RewriteLogLevel 9
</VirtualHost>


--end-----httpd.conf-----

-begin----rewrite.log-----
10.1.1.2 - - [26/Mar/2002:19:52:15 +0200] [localhost/sid#8d7ab8]
[rid#96d640/initial] (2) init rewrite engine with requested uri /fgdfgdf
10.1.1.2 - - [26/Mar/2002:19:52:15 +0200] [localhost/sid#8d7ab8]
[rid#96d640/initial] (1) pass through /fgdfgdf
10.1.1.2 - - [26/Mar/2002:19:52:15 +0200] [localhost/sid#8d7ab8]
[rid#96d640/initial] (3) [per-dir c:/program files/apache group/apache/htdocs/] 
strip per-dir prefix: c:/program files/apache group/apache/htdocs/fgdfgdf -> 
fgdfgdf
10.1.1.2 - - [26/Mar/2002:19:52:15 +0200] [localhost/sid#8d7ab8]
[rid#96d640/initial] (3) [per-dir c:/program files/apache group/apache/htdocs/] 
applying pattern '^(.*)$' to uri 'fgdfgdf'
10.1.1.2 - - [26/Mar/2002:19:52:15 +0200] [localhost/sid#8d7ab8]
[rid#96d640/initial] (2) [per-dir c:/program files/apache group/apache/htdocs/] 
rewrite fgdfgdf -> fgdfgdf/10.1.1.2
10.1.1.2 - - [26/Mar/2002:19:52:15 +0200] [localhost/sid#8d7ab8]
[rid#96d640/initial] (3) [per-dir c:/program files/apache group/apache/htdocs/] 
add per-dir prefix: fgdfgdf/10.1.1.2 -> c:/program files/apache 
group/apache/htdocs/fgdfgdf/10.1.1.2
10.1.1.2 - - [26/Mar/2002:19:52:15 +0200] [localhost/sid#8d7ab8]
[rid#96d640/initial] (3) [per-dir c:/program files/apache group/apache/htdocs/] 
add per-dir prefix: c:/program files/apache 
group/apache/htdocs/fgdfgdf/10.1.1.2 -> c:/program files/apache 
group/apache/htdocs/c:/program files/apache group/apache/htdocs/fgdfgdf/10.1.1.2
10.1.1.2 - - [26/Mar/2002:19:52:15 +0200] [localhost/sid#8d7ab8]
[rid#96d640/initial] (3) [per-dir c:/program files/apache group/apache/htdocs/] 
strip per-dir prefix: c:/program files/apache group/apache/htdocs/c:/program 
files/apache group/apache/htdocs/fgdfgdf/10.1.1.2 -> c:/program files/apache 
group/apache/htdocs/fgdfgdf/10.1.1.2
10.1.1.2 - - [26/Mar/2002:19:52:15 +0200] [localhost/sid#8d7ab8]
[rid#96d640/initial] (3) [per-dir c:/program files/apache group/apache/htdocs/] 
applying pattern '^(.*)$' to uri 'c:/program files/apache 
group/apache/htdocs/fgdfgdf/10.1.1.2'
10.1.1.2 - - [26/Mar/2002:19:52:15 +0200] [localhost/sid#8d7ab8]
[rid#96d640/initial] (5) map lookup OK: map=AntiLeech key=$1 -> val=
10.1.1.2 - - [26/Mar/2002:19:52:15 +0200] [localhost/sid#8d7ab8]
[rid#96d640/initial] (2) [per-dir c:/program files/apache group/apache/htdocs/] 
rewrite c:/program files/apache group/apache/htdocs/fgdfgdf/10.1.1.2 -> 
10.1.1.2 - - [26/Mar/2002:19:52:15 +0200] [localhost/sid#8d7ab8]
[rid#96d640/initial] (3) [per-dir c:/program files/apache group/apache/htdocs/] 
add per-dir prefix:  -> c:/program files/apache group/apache/htdocs/
10.1.1.2 - - [26/Mar/2002:19:52:15 +0200] [localhost/sid#8d7ab8]
[rid#96d640/initial] (3) [per-dir c:/program files/apache group/apache/htdocs/] 
add per-dir prefix: c:/program files/apache group/apache/htdocs/ -> c:/program 
files/apache group/apache/htdocs/c:/program files/apache group/apache/htdocs/
--end-----rewrite.log-----
Comment 1 Joshua Slive 2002-03-26 22:14:07 UTC
Could you please describe the exact problem you are experiencing?  Is it the 
fact that the key is not getting substituted properly in the RewriteMap?

You obviously have problems with the per-dir prefix getting added more than
once, but that is because you aren't using RewriteBase like you should be.
Or alternatively, you should not place the RewriteRules inside a
<Directory> section.
Comment 2 Yuriy Ryabikov 2002-03-27 07:54:16 UTC
Created attachment 1431 [details]
httpd.conf
Comment 3 Yuriy Ryabikov 2002-03-27 07:54:53 UTC
Created attachment 1432 [details]
rewrite.log
Comment 4 Yuriy Ryabikov 2002-03-27 07:55:35 UTC
Created attachment 1433 [details]
perl CGI
Comment 5 Yuriy Ryabikov 2002-03-27 08:22:30 UTC
Joshua,

Thank you for reply.
Please take a look at the line from rewrite log:
  map lookup OK: map=AntiLeech key=$1 -> val=
1. back-reference to pattern does is not resolved to URI as it should be,
when used within rewrite-map reference
  RewriteRule ^(.*)$ ${AntiLeech:$1|/leech2.html}
2. rewrite map program does not receive any input, as it's evident from empty
perl log, which I forgot to mention, and turned off buffering in attached perl
script.
3. This bug is exposed only under Win32. Under UNIX RewriteMap works ok,
all vars are subsituted, and per-dir prefix is added only once (latter may be
because of slightly different directory layout, but that's another issue. BTW,
RewriteBase does not help).

Comment 6 Joshua Slive 2002-03-27 15:03:50 UTC
OK.  I'm not sure if prg: rewritemaps have ever worked in win32.  I'm
updating the summary to better direct attention.
Comment 7 Yuriy Ryabikov 2002-03-27 15:07:23 UTC
May be will fixed in next version? ^)
Comment 8 William A. Rowe Jr. 2002-04-19 18:47:48 UTC
This bug is difficult to address in Apache 1.3.x.  Not impossible, but
difficult.  As guessed, this has never worked in the 1.3 series.

Apache 2.0.x introduced new APIs for determining fully qualified path
names.  Mod_rewrite in Apache 2.0 was updated in v. 1.84 to accept 
any rooted path (based on the filesystem convention, e.g. c:/foo for 
win32, or foo/bar:bleh for Netware.)

http://cvs.apache.org/viewcvs/httpd-2.0/modules/mappers/mod_rewrite.c.diff?r1=1.83&r2=1.84&diff_format=h

There may also be thread saftey problems with the rewrite cache,
introduced in Apache 2.0's v. 1.83, that would need backporting.

http://cvs.apache.org/viewcvs/httpd-2.0/modules/mappers/mod_rewrite.c.diff?r1=1.82&r2=1.83&diff_format=h

Finally, it seems that ap_pstrcat is still being used to merge paths
in 1.3 and 2.0.  This should be fixed in 2.0 to use apr_filepath_merge,
and there was a similar API in 1.3.

So this can be fixed, but someone needs to take the time to write and
test the fixes.  I'd entertain applying a patch that was well thought out.

Comment 9 William A. Rowe Jr. 2002-04-22 17:11:20 UTC
  Patch applied, this report will be resolved in 1.3.26.  Thread saftey of
  the rewrite cache remains an issue, creating a new incident for tracking
  thread saftey.
Comment 10 William A. Rowe Jr. 2002-04-22 17:41:55 UTC
  Make that, fixed in the forthcoming 1.3.25.
Comment 11 Jeff Trawick 2002-10-10 11:17:07 UTC
*** Bug 8424 has been marked as a duplicate of this bug. ***
Comment 12 Metin Savignano 2003-03-30 14:30:31 UTC
I stepped into this bug, too. Then I found this bug report, downloaded Apache
1.3.27, but I still have the same problem! 

My .htaccess:

RewriteEngine On
RewriteRule ^vpserve.php - [L]
RewriteRule ^(.*) vpserve.php 

The resulting rewrite log:

127.0.0.1 - - [30/Mar/2003:16:11:11 +0200]
[vp.savignano.local/sid#5d82c8][rid#682450/initial] (3) [per-dir
c:/themen/sss/htdocs/_tests/vistapoint/] add path-info postfix:
c:/themen/sss/htdocs/_tests/vistapoint -> c:/themen/sss/htdocs/_tests/vistapoint/
127.0.0.1 - - [30/Mar/2003:16:11:11 +0200]
[vp.savignano.local/sid#5d82c8][rid#682450/initial] (3) [per-dir
c:/themen/sss/htdocs/_tests/vistapoint/] strip per-dir prefix:
c:/themen/sss/htdocs/_tests/vistapoint/ -> 
127.0.0.1 - - [30/Mar/2003:16:11:11 +0200]
[vp.savignano.local/sid#5d82c8][rid#682450/initial] (3) [per-dir
c:/themen/sss/htdocs/_tests/vistapoint/] applying pattern '^vpserve.php' to uri ''
127.0.0.1 - - [30/Mar/2003:16:11:11 +0200]
[vp.savignano.local/sid#5d82c8][rid#682450/initial] (3) [per-dir
c:/themen/sss/htdocs/_tests/vistapoint/] add path-info postfix:
c:/themen/sss/htdocs/_tests/vistapoint -> c:/themen/sss/htdocs/_tests/vistapoint/
127.0.0.1 - - [30/Mar/2003:16:11:11 +0200]
[vp.savignano.local/sid#5d82c8][rid#682450/initial] (3) [per-dir
c:/themen/sss/htdocs/_tests/vistapoint/] strip per-dir prefix:
c:/themen/sss/htdocs/_tests/vistapoint/ -> 
127.0.0.1 - - [30/Mar/2003:16:11:11 +0200]
[vp.savignano.local/sid#5d82c8][rid#682450/initial] (3) [per-dir
c:/themen/sss/htdocs/_tests/vistapoint/] applying pattern '^(.*)' to uri ''
127.0.0.1 - - [30/Mar/2003:16:11:11 +0200]
[vp.savignano.local/sid#5d82c8][rid#682450/initial] (2) [per-dir
c:/themen/sss/htdocs/_tests/vistapoint/] rewrite  -> vpserve.php
127.0.0.1 - - [30/Mar/2003:16:11:11 +0200]
[vp.savignano.local/sid#5d82c8][rid#682450/initial] (3) [per-dir
c:/themen/sss/htdocs/_tests/vistapoint/] add per-dir prefix: vpserve.php ->
c:/themen/sss/htdocs/_tests/vistapoint/vpserve.php
127.0.0.1 - - [30/Mar/2003:16:11:11 +0200]
[vp.savignano.local/sid#5d82c8][rid#682450/initial] (3) [per-dir
c:/themen/sss/htdocs/_tests/vistapoint/] add per-dir prefix:
c:/themen/sss/htdocs/_tests/vistapoint/vpserve.php ->
c:/themen/sss/htdocs/_tests/vistapoint/c:/themen/sss/htdocs/_tests/vistapoint/vpserve.php

For some reason, the directroy preix is still added twice.

I re-opened the bug, but a work-around hint would be helpful as well.
Comment 13 Metin Savignano 2003-03-30 19:37:21 UTC
Sorry, I missed the fact that the modules were changed from .dll to .so in some
version, and did not update the httpd.conf accordingly.

I discovered this a few minutes ago and corrected the mistake. Now it works
flawlessly.

Mea culpa!