You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Jon Drukman <js...@cluttered.com> on 2006/03/18 00:02:26 UTC

[users@httpd] mod_rewrite doesn't always prefix with document_root

I've got the following rule in my config:

rewriterule ^/e3/(.*) /misc/e3/$1 [L]

It doesn't work.  If I change the "/misc" to "/test", it does.

Here's what's in the rewrite log for the bad case:  (edited for brevity)

(2) init rewrite engine with requested uri /e3/index.html
(3) applying pattern '\.ini$' to uri '/e3/index.html'
(3) applying pattern '^/e3/(.*)' to uri '/e3/index.html'
(2) rewrite /e3/index.html -> /misc/e3/index.html
(2) local path result: /misc/e3/index.html
(1) go-ahead with /misc/e3/index.html [OK]

Here's the good case:

(2) init rewrite engine with requested uri /e3/index.html
(3) applying pattern '\.ini$' to uri '/e3/index.html'
(3) applying pattern '^/e3/(.*)' to uri '/e3/index.html'
(2) rewrite /e3/index.html -> /test/e3/index.html
(2) local path result: /test/e3/index.html
(2) prefixed with document_root to /var/httpd/sandbox/test/e3/index.html
(1) go-ahead with /var/httpd/sandbox/test/e3/index.html [OK]


Notice how in the good case it's doing "prefixed with document_root 
to..."  Why would it skip that in the first case?  Is it because I have 
a /misc directory on my filesystem?  How do I get it to always look 
within the document_root first?

-jsd-


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


[users@httpd] Re: mod_rewrite doesn't always prefix with document_root

Posted by Jon Drukman <js...@cluttered.com>.
Joshua Slive wrote:
> On 3/17/06, Jon Drukman <js...@cluttered.com> wrote:
> 
>>I've got the following rule in my config:
>>
>>rewriterule ^/e3/(.*) /misc/e3/$1 [L]
>>
>>It doesn't work.  If I change the "/misc" to "/test", it does.
> 
> 
> Do you happen to have a /misc/e3 directory off your filesystem root? 
> If so, mod_rewrite assumes you want that.

i have a /misc but no /misc/e3.  i can work around it using robert's 
suggestion.

-jsd-


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite doesn't always prefix with document_root

Posted by Joshua Slive <jo...@slive.ca>.
On 3/17/06, Jon Drukman <js...@cluttered.com> wrote:
> I've got the following rule in my config:
>
> rewriterule ^/e3/(.*) /misc/e3/$1 [L]
>
> It doesn't work.  If I change the "/misc" to "/test", it does.

Do you happen to have a /misc/e3 directory off your filesystem root? 
If so, mod_rewrite assumes you want that.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


[users@httpd] Re: mod_rewrite doesn't always prefix with document_root

Posted by Jon Drukman <js...@cluttered.com>.
Jon Drukman wrote:
> is there a way to substitute the documentroot variable instead of 
> hardcoding it?  we have the same rewrite file used by many many 
> virtualhosts, and being able to refer to just /misc/whatever and have it 
> automatically map to the correct docroot would be extremely valuable.

i should have just RTFM... the answer is %{DOCUMENT_ROOT}

i'm all set now, thanks


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


[users@httpd] Re: mod_rewrite doesn't always prefix with document_root

Posted by Jon Drukman <js...@cluttered.com>.
Robert Ionescu wrote:
> Jon Drukman wrote:
> 
>> Notice how in the good case it's doing "prefixed with document_root 
>> to..."  Why would it skip that in the first case?  Is it because I 
>> have a /misc directory on my filesystem?
> 
> 
> Exactly, that's normal behavior in per-server context.
> 
>> How do I get it to always look within the document_root first
> 
> 
> Prefix your substitution with the DocumentRoot, so that it becomes a 
> full physical path
> 
> rewriterule ^/e3/(.*) /var/httpd/sandbox/misc/e3/$1 [L]
> 

is there a way to substitute the documentroot variable instead of 
hardcoding it?  we have the same rewrite file used by many many 
virtualhosts, and being able to refer to just /misc/whatever and have it 
automatically map to the correct docroot would be extremely valuable.

the idea that adding or removing top level directories could change the 
behavior of my rewriterules is disturbing...

-jsd-


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite doesn't always prefix with document_root

Posted by Robert Ionescu <ro...@googlemail.com>.
Jon Drukman wrote:
> Notice how in the good case it's doing "prefixed with document_root 
> to..."  Why would it skip that in the first case?  Is it because I have 
> a /misc directory on my filesystem?

Exactly, that's normal behavior in per-server context.

> How do I get it to always look within the document_root first

Prefix your substitution with the DocumentRoot, so that it becomes a 
full physical path

rewriterule ^/e3/(.*) /var/httpd/sandbox/misc/e3/$1 [L]

-- 
Robert

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org