12, March 2010

mod_rewrite on Apache2.2 - webmaster forum

 
Webdigity webmaster forums
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web hosting talk  >  Configuring your server  >  Apache web server
Topic: mod_rewrite on Apache2.2
« previous next »
Pages: [1] 2 Print

Author Topic: mod_rewrite on Apache2.2  (Read 1301 times)
Sandwich Artist
*
Posts: 24
152 credits
Members referred : 0


« on: May 20, 2009, 04:02:26 pm »

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.
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6690
34708 credits
Members referred : 374


It's time to use PHP5!


« Reply #1 on: May 20, 2009, 08:28:03 pm »

maybe you can show us some example URL's?


Last blog : A new Wordpress theme for our blog
Sandwich Artist
*
Posts: 24
152 credits
Members referred : 0


« Reply #2 on: May 21, 2009, 12:09:01 pm »

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?
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6690
34708 credits
Members referred : 374


It's time to use PHP5!


« Reply #3 on: May 21, 2009, 12:11:57 pm »

never used mod_rewite on an IP address, do you checked the rewrite log files?

is this your production environment? using apache on windows?


Last blog : A new Wordpress theme for our blog
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6690
34708 credits
Members referred : 374


It's time to use PHP5!


« Reply #4 on: May 21, 2009, 12:12:54 pm »

change this row:

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


Last blog : A new Wordpress theme for our blog
Sandwich Artist
*
Posts: 24
152 credits
Members referred : 0


« Reply #5 on: May 21, 2009, 12:15:51 pm »

I'm using Apache 2.2 on Windows.
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6690
34708 credits
Members referred : 374


It's time to use PHP5!


« Reply #6 on: May 21, 2009, 12:17:32 pm »

I'm using Apache 2.2 on Windows.

for production, a URL rewriting service?


Last blog : A new Wordpress theme for our blog
Sandwich Artist
*
Posts: 24
152 credits
Members referred : 0


« Reply #7 on: May 21, 2009, 12:19:50 pm »

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.
Sandwich Artist
*
Posts: 24
152 credits
Members referred : 0


« Reply #8 on: May 21, 2009, 12:21:15 pm »

It's for production.  The site maps the folders and generates URLs on the fly then loads them.
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6690
34708 credits
Members referred : 374


It's time to use PHP5!


« Reply #9 on: May 21, 2009, 12:23:57 pm »

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?


Last blog : A new Wordpress theme for our blog
Sandwich Artist
*
Posts: 24
152 credits
Members referred : 0


« Reply #10 on: May 21, 2009, 12:27:21 pm »

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
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6690
34708 credits
Members referred : 374


It's time to use PHP5!


« Reply #11 on: May 21, 2009, 12:32:55 pm »

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"


Last blog : A new Wordpress theme for our blog
Sandwich Artist
*
Posts: 24
152 credits
Members referred : 0


« Reply #12 on: May 21, 2009, 12:39:48 pm »

Can you be a bit more specific?  Where do you want me to put the slash?
Sandwich Artist
*
Posts: 24
152 credits
Members referred : 0


« Reply #13 on: May 21, 2009, 12:45:36 pm »

Would it be safer to use the mod_rewrite rule on a http address instead?  If so, any pointers on this topic?
Sandwich Artist
*
Posts: 24
152 credits
Members referred : 0


« Reply #14 on: May 21, 2009, 12:56:47 pm »

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
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6690
34708 credits
Members referred : 374


It's time to use PHP5!


« Reply #15 on: May 21, 2009, 01:44:33 pm »

is this the path you need?

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


Last blog : A new Wordpress theme for our blog
Sandwich Artist
*
Posts: 24
152 credits
Members referred : 0


« Reply #16 on: May 21, 2009, 05:53:36 pm »

No.  The location is:

192.168.0.6:3128/index.php

Where '192.168.0.6:3128' is my virtual server.
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6690
34708 credits
Members referred : 374


It's time to use PHP5!


« Reply #17 on: May 21, 2009, 06:19:52 pm »

maybe you need to include the port number to and the colon to your pattern?


Last blog : A new Wordpress theme for our blog
Sandwich Artist
*
Posts: 24
152 credits
Members referred : 0


« Reply #18 on: May 22, 2009, 01:11:03 pm »

The problem is sorted. 

Thanks.
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6690
34708 credits
Members referred : 374


It's time to use PHP5!


« Reply #19 on: May 22, 2009, 01:17:09 pm »

The problem is sorted. 

Thanks.
what was wrong? the missing colon?


Last blog : A new Wordpress theme for our blog
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=8788
Tags : <> Bookmark this thread : Digg Del.icio.us Dzone more....

Pages: [1] 2 Print 
Webdigity Webmaster Forums  >  Web hosting talk  >  Configuring your server  >  Apache web server
Topic: mod_rewrite on Apache2.2
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Mar 12, 2010, 06:38:32 am





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!





Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2010 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.