You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Klavs Klavsen <kl...@vsen.dk> on 2003/06/04 17:23:14 UTC

[users@httpd] rewrite problem

Hi guys,

I've spent several days on this problem of mine (incl. googleing) and
now I'm forced to ask you.

I've tried this with both apache-1.3 and 2.0.46.

I need to use the mod_vhost_alias directive
VirtualDocumentRoot.
I've set to Documentroot to /www and I am then using 
virtualdocumentroot /www/-2/html 
to automatically map the user to the correct path.

f.ex. www.test.dk becomes /www/test/html/

It works flawlessly.

Now comes the problem.

I have a long list of rewriterules, which rewrite from f.ex. Page-1.html
to index.php?pageid=1 and so forth. But if I use the plain rewriterule
(which works in a normal virtualhost) it tries to find the index.php
file at the DocumentRoot (which is /www) instead of at the
VirtualDocumentRoot). :(

I've been reading up on how to fix this, and have tried several things.
My latest try is this, which I can't seem to figure out why it doesn't
work:

Options FollowSymLinks

RewriteEngine On
RewriteOptions 'inherit'

RewriteMap lowercase int:tolower

# don't try to urls not ending in .html
RewriteRule !^([^/]*)/([^/]+)\.html$ - [L]

# match www.*.*
RewriteCond   %{HTTP_HOST}              ^www\.[^.]+\.[^-]+$ [NC]
RewriteRule   ^(.+)                     ${lowercase:%{HTTP_HOST}}$1 [C]
RewriteRule   ^www\.([^.]+)\.([^/.]+)(.*)       $3      [E=VHOST:$1,PT]

# match *.*
RewriteCond   %{HTTP_HOST}              ^[^.]+\.[^-]+$ [NC]
RewriteRule   ^(.+)                     ${lowercase:%{HTTP_HOST}}$1 [C]
RewriteRule   ^([^.]+)\.([^/.]+)(.*)    $3              [E=VHOST:$1,PT]

# rewrite Page-(id).html
RewriteRule (.*)/Page-([0-9]+)\.html$
%{ENV:VHOST}/html/$1index.php?pageid=$2 [L,NS]

This works, according to the rewrite.log:

] (3) applying pattern '^([^/]*)/([^/]+)\.html$' to uri '/Page-3.html'
192.168.1.4 - - [04/Jun/2003:15:58:47 +0200]
[defaulttest.dk/sid#8113c08][rid#822fa48/initial
] (3) applying pattern '^(.+)' to uri '/Page-3.html'
192.168.1.4 - - [04/Jun/2003:15:58:47 +0200]
[defaulttest.dk/sid#8113c08][rid#822fa48/initial
] (4) RewriteCond: input='defaulttest.dk' pattern='^www\.[^.]+\.[^-]+$'
=> not-matched
192.168.1.4 - - [04/Jun/2003:15:58:47 +0200]
[defaulttest.dk/sid#8113c08][rid#822fa48/initial
] (3) applying pattern '^(.+)' to uri '/Page-3.html'
192.168.1.4 - - [04/Jun/2003:15:58:47 +0200]
[defaulttest.dk/sid#8113c08][rid#822fa48/initial
] (4) RewriteCond: input='defaulttest.dk' pattern='^[^.]+\.[^-]+$' =>
matched
192.168.1.4 - - [04/Jun/2003:15:58:47 +0200]
[defaulttest.dk/sid#8113c08][rid#822fa48/initial
] (5) map lookup OK: map=lowercase key=defaulttest.dk ->
val=defaulttest.dk
192.168.1.4 - - [04/Jun/2003:15:58:47 +0200]
[defaulttest.dk/sid#8113c08][rid#822fa48/initial
] (2) rewrite /Page-3.html -> defaulttest.dk/Page-3.html
192.168.1.4 - - [04/Jun/2003:15:58:47 +0200]
[defaulttest.dk/sid#8113c08][rid#822fa48/initial
] (3) applying pattern '^([^.]+)\.([^/.]+)(.*)' to uri
'defaulttest.dk/Page-3.html'
192.168.1.4 - - [04/Jun/2003:15:58:47 +0200]
[defaulttest.dk/sid#8113c08][rid#822fa48/initial
] (2) rewrite defaulttest.dk/Page-3.html -> /Page-3.html
192.168.1.4 - - [04/Jun/2003:15:58:47 +0200]
[defaulttest.dk/sid#8113c08][rid#822fa48/initial
] (5) setting env variable 'domain' to 'defaulttest'
192.168.1.4 - - [04/Jun/2003:15:58:47 +0200]
[defaulttest.dk/sid#8113c08][rid#822fa48/initial
] (3) applying pattern '(.*)/Page-([0-9]+)\.html$' to uri '/Page-3.html'
192.168.1.4 - - [04/Jun/2003:15:58:47 +0200]
[defaulttest.dk/sid#8113c08][rid#822fa48/initial
] (2) rewrite /Page-3.html ->
defaulttest/html/index.php?name=PagEd&page_id=3
192.168.1.4 - - [04/Jun/2003:15:58:47 +0200]
[defaulttest.dk/sid#8113c08][rid#822fa48/initial
] (3) split uri=defaulttest/html/index.php?pageid=3 ->
uri=defaulttest/html/index
.php, args=name=PagEd&page_id=3
192.168.1.4 - - [04/Jun/2003:15:58:47 +0200]
[defaulttest.dk/sid#8113c08][rid#822fa48/initial
] (2) local path result: defaulttest/html/index.php

But the error log says:

 Invalid URI in request GET /Page-3.html HTTP/1.1

Any ideas?

Thankyou in advance.


-- 
Regards,
Klavs Klavsen, GSEC - kl@vsen.dk - http://www.vsen.dk

Working with Unix is like wrestling a worthy opponent. 
Working with windows is like attacking a small whining child 
who is carrying a .38.