file-system path substitution for RewriteRule in .htaccess not working as documented

Bug #174282 reported by Daniel Hahler
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
apache2 (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

Binary package hint: apache2

According to http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule it should work like that:
file-system path
  Designates the location on the file-system of the resource to be delivered to the client.
URL-path
  A DocumentRoot-relative path to the resource to be served. Note that mod_rewrite tries to guess whether you have specified a file-system path or a URL-path by checking to see if the first segement of the path exists at the root of the file-system. For example, if you specify a Substitution string of /www/file.html, then this will be treated as a URL-path unless a directory named www exists at the root or your file-system, in which case it will be treated as a file-system path. If you wish other URL-mapping directives (such as Alias) to be applied to the resulting URL-path, use the [PT] flag as described below.

TEST CASE:
1. Create a .htaccess file with the following lines, for e.g. http://localhost/:
  RewriteEngine On
  RewriteRule foo /tmp/bar.tmp
2. touch /tmp/bar.tmp
3. Access http://localhost/foo

ACTUAL RESULT:
You get an error page "The requested URL /tmp/bar.tmp was not found on this server.", because the substitution gets interpreted as URL relative to DocumentRoot

EXPECTED:
The file /tmp/bar.tmp gets served.

RewriteLog (at level 9):
[rid#8401900/initial] (2) init rewrite engine with requested uri /foo
[rid#8401900/initial] (1) pass through /foo
[rid#8401900/initial] (3) [perdir /var/www/] strip per-dir prefix: /var/www/foo -> foo
[rid#8401900/initial] (3) [perdir /var/www/] applying pattern 'foo' to uri 'foo'
[rid#8401900/initial] (2) [perdir /var/www/] rewrite 'foo' -> '/tmp/bar.tmp'
[rid#8401900/initial] (1) [perdir /var/www/] internal redirect with /tmp/bar.tmp [INTERNAL REDIRECT]
[rid#840bfe0/initial/redir#1] (2) init rewrite engine with requested uri /tmp/bar.tmp
[rid#840bfe0/initial/redir#1] (1) pass through /tmp/bar.tmp
[rid#840bfe0/initial/redir#1] (3) [perdir /var/www/] add path info postfix: /var/www/tmp -> /home/da
[rid#840bfe0/initial/redir#1] (3) [perdir /var/www/] strip per-dir prefix: /var/www/tmp/bar.tmp -> t
[rid#840bfe0/initial/redir#1] (3) [perdir /var/www/] applying pattern 'foo' to uri 'tmp/bar.tmp'
[rid#840bfe0/initial/redir#1] (1) [perdir /var/www/] pass through /var/www/tmp

Revision history for this message
Marnen Laibow-Koser (marnen) wrote :

Confirmed. Happening for me too.

Revision history for this message
Herbert Straub (herbert) wrote :

I think, Apache works correctly. In my opinion, I cannot expect, that a simple .htaccess file in a directory serves the /etc/passwd and /etc/shadow file, for example. If you place this RewriteRule in the default file (for example), not in a .htaccess file, then the /tmp/bar.tmp are served. See the documentation for details:

http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule
--> Per-directory Rewrites

http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html

Log with RewriteRule in .htaccess:
[perdir /var/www/] strip per-dir prefix: /var/www/foo -> foo
[perdir /var/www/] applying pattern 'foo' to uri 'foo'
[perdir /var/www/] rewrite 'foo' -> '/tmp/bar.tmp'
[perdir /var/www/] internal redirect with /tmp/bar.tmp [INTERNAL REDIRECT]
[perdir /var/www/] add path info postfix: /var/www/tmp -> /var/www/tmp/bar.tmp
[perdir /var/www/] strip per-dir prefix: /var/www/tmp/bar.tmp -> tmp/bar.tmp
[perdir /var/www/] applying pattern 'foo' to uri 'tmp/bar.tmp'
[perdir /var/www/] pass through /var/www/tmp

Log with RewriteRule in default:
init rewrite engine with requested uri /foo
applying pattern '/foo' to uri '/foo'
rewrite '/foo' -> '/tmp/bar.tmp'
local path result: /tmp/bar.tmp
go-ahead with /tmp/bar.tmp [OK]

Revision history for this message
Chuck Short (zulcss) wrote :

Which version of apache are you using when you encounter this bug?

Thanks
chuck

Revision history for this message
Chuck Short (zulcss) wrote :

Is this still a problem for you in hardy?

Thanks
chuck

Changed in apache2:
status: New → Incomplete
Revision history for this message
Mackenzie Morgan (maco.m) wrote :

We are closing this bug report because it lacks the information we need to investigate the problem, as described in the previous comments. Please reopen it if you can give us the missing information, and don't hesitate to submit bug reports in the future. To reopen the bug report you can click on the current status, under the Status column, and change the Status back to "New". Thanks again!

If you are still experiencing this bug in Hardy or Intrepid, please reopen.

Changed in apache2:
status: Incomplete → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.