Sublime directory Surf the web anonymous Pagerank Monitor


mod_rewrite on Apache2.2

Jim
Wed 20 May 2009, 03:02 pm GMT +0200
Hello all,

I'm currently setting up my server to host a website that generates URLs on the fly.  I've inserted this code into my .httpd file.  This code rewrites each request and finds the correct folder.  The snippet of code is:

<VirtualHost 192.168.0.6:3128>

 
  <Directory "/var/www/">
Options Indexes FollowSymLinks
AllowOverride none
Order allow,deny
Allow from all
  </Directory>

  ServerName site1.local
  DocumentRoot /var/www/
  RewriteEngine on
  RewriteMap lowercase int:tolower

  RewriteCond ${lowercase:%{SERVER_NAME}} ^[a-z0-9-]+.[.a-z0-9-]+$
  RewriteRule ^(.+) ${lowercase:%{SERVER_NAME}}$1 [C]
  RewriteRule ^([a-z0-9-]+).([a-z0-9-.]+)/(.*) /var/www/$2/$1/$3
   

</VirtualHost>

However, whenever I run index.php I get this error message:

The requested URL /index.php was not found on this server.

I've checked my error log and found that Apache adds a folder onto my URL.  Here is an exert from my error log:

[error] [client 192.168.0.6] File does not exist: C:/var/www/var

As you can see it has added the folder 'var' onto the end of my root.  Therefore when my server looks for index.php it can't find it.  I need to keep the code that instructs apache to re-write each incoming request to find the right folder for it, but how do I stop it adding a new folder onto the end?  I'm quite new to the mod_rewrite function so any help would be great.

Jim.

olaf
Wed 20 May 2009, 07:28 pm GMT +0200
maybe you can show us some example URL's?

Jim
Thu 21 May 2009, 11:09 am GMT +0200
My URL displays: "http://192.168.0.6:3128/index.php"
While mt error-log displays:

192.168.0.6 - - [21/May/2009:10:02:52 +0100] [192.168.0.6/sid#6b49d0][rid#fe0e20/initial] (5) map lookup OK: map=lowercase key=192.168.0.6 -> val=192.168.0.6
192.168.0.6 - - [21/May/2009:10:02:52 +0100] [192.168.0.6/sid#6b49d0][rid#fe0e20/initial] (4) RewriteCond: input='192.168.0.6' pattern='^[a-z0-9-]+.[.a-z0-9-]+$' => matched
192.168.0.6 - - [21/May/2009:10:02:52 +0100] [192.168.0.6/sid#6b49d0][rid#fe0e20/initial] (5) map lookup OK: map=lowercase key=192.168.0.6 -> val=192.168.0.6
192.168.0.6 - - [21/May/2009:10:02:52 +0100] [192.168.0.6/sid#6b49d0][rid#fe0e20/initial] (2) rewrite '/index.php' -> '192.168.0.6/index.php'
192.168.0.6 - - [21/May/2009:10:02:52 +0100] [192.168.0.6/sid#6b49d0][rid#fe0e20/initial] (3) applying pattern '^([a-z0-9-]+).([a-z0-9-.]+)/(.*)' to uri '192.168.0.6/index.php'
192.168.0.6 - - [21/May/2009:10:02:52 +0100] [192.168.0.6/sid#6b49d0][rid#fe0e20/initial] (2) rewrite '192.168.0.6/index.php' -> '/var/www/168.0.6/192/index.php'
192.168.0.6 - - [21/May/2009:10:02:52 +0100] [192.168.0.6/sid#6b49d0][rid#fe0e20/initial] (2) local path result: /var/www/168.0.6/192/index.php
192.168.0.6 - - [21/May/2009:10:02:52 +0100] [192.168.0.6/sid#6b49d0][rid#fe0e20/initial] (2) prefixed with document_root to C:/var/www/var/www/168.0.6/192/index.php
192.168.0.6 - - [21/May/2009:10:02:52 +0100] [192.168.0.6/sid#6b49d0][rid#fe0e20/initial] (1) go-ahead with C:/var/www/var/www/168.0.6/192/index.php [OK]

Any pointers?

olaf
Thu 21 May 2009, 11:11 am GMT +0200
never used mod_rewite on an IP address, do you checked the rewrite log files?

is this your production environment? using apache on windows?

olaf
Thu 21 May 2009, 11:12 am GMT +0200
change this row:

  RewriteRule ^([a-z0-9-]+).([a-z0-9-.]+)/(.*) $2/$1/$3

Jim
Thu 21 May 2009, 11:15 am GMT +0200
I'm using Apache 2.2 on Windows.

olaf
Thu 21 May 2009, 11:17 am GMT +0200
I'm using Apache 2.2 on Windows.

for production, a URL rewriting service?

Jim
Thu 21 May 2009, 11:19 am GMT +0200
I've just changed the line and the website give me a Bad Request and tells me that my server can't understand the request.

Jim
Thu 21 May 2009, 11:21 am GMT +0200
It's for production.  The site maps the folders and generates URLs on the fly then loads them.

olaf
Thu 21 May 2009, 11:23 am GMT +0200
It's for production.  The site maps the folders and generates URLs on the fly then loads them.

I'm sure some real traffic will break your configuration, use PHP + IIS instead

what is the error log for the modified row?

Jim
Thu 21 May 2009, 11:27 am GMT +0200
I have to use Apache.  The site consists of ten pages.  each pages URL is generated on the fly and loads it into the site.  The log errors are:

192.168.0.6 - - [21/May/2009:10:16:53 +0100] [192.168.0.6/sid#6b49d0][rid#fe0e20/initial] (2) init rewrite engine with requested uri /index.php
192.168.0.6 - - [21/May/2009:10:16:53 +0100] [192.168.0.6/sid#6b49d0][rid#fe0e20/initial] (3) applying pattern '^(.+)' to uri '/index.php'
192.168.0.6 - - [21/May/2009:10:16:53 +0100] [192.168.0.6/sid#6b49d0][rid#fe0e20/initial] (5) map lookup OK: map=lowercase key=192.168.0.6 -> val=192.168.0.6
192.168.0.6 - - [21/May/2009:10:16:53 +0100] [192.168.0.6/sid#6b49d0][rid#fe0e20/initial] (4) RewriteCond: input='192.168.0.6' pattern='^[a-z0-9-]+.[.a-z0-9-]+$' => matched
192.168.0.6 - - [21/May/2009:10:16:53 +0100] [192.168.0.6/sid#6b49d0][rid#fe0e20/initial] (5) map lookup OK: map=lowercase key=192.168.0.6 -> val=192.168.0.6
192.168.0.6 - - [21/May/2009:10:16:53 +0100] [192.168.0.6/sid#6b49d0][rid#fe0e20/initial] (2) rewrite '/index.php' -> '192.168.0.6/index.php'
192.168.0.6 - - [21/May/2009:10:16:53 +0100] [192.168.0.6/sid#6b49d0][rid#fe0e20/initial] (3) applying pattern '^([a-z0-9-]+).([a-z0-9-.]+)/(.*)' to uri '192.168.0.6/index.php'
192.168.0.6 - - [21/May/2009:10:16:53 +0100] [192.168.0.6/sid#6b49d0][rid#fe0e20/initial] (2) rewrite '192.168.0.6/index.php' -> '168.0.6/192/index.php'
192.168.0.6 - - [21/May/2009:10:16:53 +0100] [192.168.0.6/sid#6b49d0][rid#fe0e20/initial] (2) local path result: 168.0.6/192/index.php

olaf
Thu 21 May 2009, 11:32 am GMT +0200
the server stops before these rows:

192.168.0.6 - - [21/May/2009:10:02:52 +0100] [192.168.0.6/sid#6b49d0][rid#fe0e20/initial] (2) prefixed with document_root to C:/var/www/var/www/168.0.6/192/index.php
192.168.0.6 - - [21/May/2009:10:02:52 +0100] [192.168.0.6/sid#6b49d0][rid#fe0e20/initial] (1) go-ahead with C:/var/www/var/www/168.0.6/192/index.php [OK]

do you tried to ad a slash before "RewriteRule ^([a-z0-9-]+).([a-z0-9-.]+)/(.*) $2/$1/$3"

Jim
Thu 21 May 2009, 11:39 am GMT +0200
Can you be a bit more specific?  Where do you want me to put the slash?

Jim
Thu 21 May 2009, 11:45 am GMT +0200
Would it be safer to use the mod_rewrite rule on a http address instead?  If so, any pointers on this topic?

Jim
Thu 21 May 2009, 11:56 am GMT +0200
I've just put the slash in before the RewriteRule and it doesn't work.  Same error message.

192.168.0.6 - - [21/May/2009:10:53:39 +0100] [192.168.0.6/sid#6b49d0][rid#fe0e20/initial] (3) applying pattern '\.^([a-z0-9-]+).([a-z0-9-.]+)/(.*)' to uri '192.168.0.6/index.php'
192.168.0.6 - - [21/May/2009:10:53:39 +0100] [192.168.0.6/sid#6b49d0][rid#fe0e20/initial] (2) local path result: 192.168.0.6/index.php

olaf
Thu 21 May 2009, 12:44 pm GMT +0200
is this the path you need?

/var/www/168.0.6/192/index.php (the real file location?)

Jim
Thu 21 May 2009, 04:53 pm GMT +0200
No.  The location is:

192.168.0.6:3128/index.php

Where '192.168.0.6:3128' is my virtual server.

olaf
Thu 21 May 2009, 05:19 pm GMT +0200
maybe you need to include the port number to and the colon to your pattern?

Jim
Fri 22 May 2009, 12:11 pm GMT +0200
The problem is sorted. 

Thanks.

olaf
Fri 22 May 2009, 12:17 pm GMT +0200
The problem is sorted. 

Thanks.
what was wrong? the missing colon?

Jim
Fri 22 May 2009, 12:22 pm GMT +0200
It turns out I only had to un-comment the mod_rewrite.  I simply delved too far into mod_rewrite.  Wasted half a day doing so though.  Still learnt something about Rewrite and RewriteCond rules in the process. 

Archive for SMF v1.00 by N.P. Valid XHTML 1.0 Transitional