Page 1 of 1

Apache, Proxy and Rewrite (I'm lost)

Posted: Tue Apr 04, 2006 4:31 am
by asgerhallas
Hi,

I have a trailing slash problem like the one described and solved in viewtopic.php?t=45842.
BUT my setup is a little different, and that breaks everything. Can't make it work!

I have an Apache2 on 80.160.xx.xx listening to port 80. Sending all requests for none existing Virtual Servers on to http://localhost:8080/, which is an Apache1.3 server. The apache 1.3 handles all my old websites on PHP4.

It works pretty well, all except for the trailing slash. When I write http://www.test.dk/tester AND /tester is a directory it wont recognize it as such and throws a 404.

My setup on the Apache1.3 server looks like this:

vhost for http://www.test.dk:

Code: Select all

<VirtualHost *:8080>
SSLDisable
DocumentRoot /web/www.test.dk/www
ServerName www.test.dk
ServerAlias test.dk
RewriteEngine On
RewriteLog "/usr/local/apache/logs/rewrite.log"
RewriteLogLevel 2
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://%{HTTP_HOST}$1/ [R,L]
DirectoryIndex index.html index.htm index.php index.php3 index.phtml
<Directory "/web/www.test.dk/">
Options +IncludesNOEXEC
</Directory>
</VirtualHost>
The log gives me the following:

Code: Select all

127.0.0.1 - - [04/Apr/2006:11:25:06 +0200] [www.test.dk/sid#820be5c][rid#81e006c/initial] (2) init rewrite engine with requested uri /tester
127.0.0.1 - - [04/Apr/2006:11:25:06 +0200] [www.test.dk/sid#820be5c][rid#81e006c/initial] (2) rewrite /tester -> http://www.test.dk/tester/
127.0.0.1 - - [04/Apr/2006:11:25:06 +0200] [www.test.dk/sid#820be5c][rid#81e006c/initial] (2) explicitly forcing redirect with http://www.test.dk/tester/
127.0.0.1 - - [04/Apr/2006:11:25:06 +0200] [www.test.dk/sid#820be5c][rid#81e006c/initial] (1) escaping http://www.test.dk/tester/ for redirect
127.0.0.1 - - [04/Apr/2006:11:25:06 +0200] [www.test.dk/sid#820be5c][rid#81e006c/initial] (1) redirect to http://www.test.dk/tester/ [REDIRECT/302]
localhost.localdomain - - [04/Apr/2006:11:25:06 +0200] [www.test.dk/sid#820be5c][rid#81e006c/initial] (2) init rewrite engine with requested uri /tester/
localhost.localdomain - - [04/Apr/2006:11:25:06 +0200] [www.test.dk/sid#820be5c][rid#81e006c/initial] (1) pass through /tester/
localhost.localdomain - - [04/Apr/2006:11:25:06 +0200] [www.test.dk/sid#820be5c][rid#832784c/subreq] (2) init rewrite engine with requested uri /tester/index.html
localhost.localdomain - - [04/Apr/2006:11:25:06 +0200] [www.test.dk/sid#820be5c][rid#832784c/subreq] (1) pass through /tester/index.html
localhost.localdomain - - [04/Apr/2006:11:25:06 +0200] [www.test.dk/sid#820be5c][rid#8245714/initial/redir#1] (2) init rewrite engine with requested uri /tester/index.html
localhost.localdomain - - [04/Apr/2006:11:25:06 +0200] [www.test.dk/sid#820be5c][rid#8245714/initial/redir#1] (2) rewrite /tester/index.html -> http://www.test.dk/tester/index.html/
localhost.localdomain - - [04/Apr/2006:11:25:06 +0200] [www.test.dk/sid#820be5c][rid#8245714/initial/redir#1] (2) explicitly forcing redirect with http://www.test.dk/tester/index.html/
localhost.localdomain - - [04/Apr/2006:11:25:06 +0200] [www.test.dk/sid#820be5c][rid#8245714/initial/redir#1] (1) escaping http://www.test.dk/tester/index.html/ for redirect
localhost.localdomain - - [04/Apr/2006:11:25:06 +0200] [www.test.dk/sid#820be5c][rid#8245714/initial/redir#1] (1) redirect to http://www.test.dk/tester/index.html/ [REDIRECT/302]
localhost.localdomain - - [04/Apr/2006:11:25:06 +0200] [www.test.dk/sid#820be5c][rid#81e006c/initial] (2) init rewrite engine with requested uri /tester/index.html/
localhost.localdomain - - [04/Apr/2006:11:25:06 +0200] [www.test.dk/sid#820be5c][rid#81e006c/initial] (1) pass through /tester/index.html/

Now my questions:
1. As you can see, the files are appended the trailing slash even though I used the "RewriteCond %{REQUEST_FILENAME} !-f". Why??
2. There are some subreq and initial and inital/redi in the log - what does that mean?
3. Does anybody now a solution to this?

/Asger

Posted: Tue Apr 04, 2006 2:37 pm
by asgerhallas
At last I got it now! :)

If anybody else got the problem, the solution was NOT to use rewrite, as apache1.3 already before it reaches the rewriterules does a redirect beacuse of the missing slash. Mod_dir does this, and mod_dir thinks the webservers name was http://www.test.dk:8080/tester/, but the apache1.3 only listens to the localhost for incoming calls, and so this EXTERNAL redirect doesn't make sense. Just put "ServerName http://www.test.dk" and "Port 80" in the virtual host on the apache1.3, this way mod_dir will use these informations in the redirect.

/Asger