homepage Welcome to WebmasterWorld Guest from 54.166.105.24
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Mod Rewrite and Bad Requests
This is destroying me slowly
deckchirboy




msg:1520189
 1:44 pm on Jul 23, 2003 (gmt 0)

Hi All, yes more mod rewrite woes, I have been bashing my brains out over this for so long that I cannot bear to leave it because of the wasted investment in time if I do.

I am running apache2 on windows XP and I can get mod rewrite to work but the server then falls over and cannot fulfill the request. I have reduced the rewrite rule to its most basic level I think but still no joy.

Here is the rewrite rule from httpd.conf-it is really trivial but illustrates the problem. If the request contains the word paul it is rewritten to /paul/index.html.

I turn the rewrite engine off and type localhost/paul/index.html and the page loads (impressed huh)
I turn the engine on and retype the url which is rewritten to exactly the same form as it was received but it then generates a bad request..

RewriteEngine on
RewriteLog "C:/Server/Apache2/logs/rewrite.log"
RewriteLogLevel 9
RewriteCond %{THE_REQUEST} paul

RewriteRule paul /paul/index.html [L]

Here is the rewrite log file section.

127.0.0.1 - - [23/Jul/2003:13:50:54 +0100] [localhost/sid#32b5b8][rid#642690/initial] (2) init rewrite engine with requested uri /paul/index.html
127.0.0.1 - - [23/Jul/2003:13:50:54 +0100] [localhost/sid#32b5b8][rid#642690/initial] (3) applying pattern 'paul' to uri '/paul/index.html'
127.0.0.1 - - [23/Jul/2003:13:50:54 +0100] [localhost/sid#32b5b8][rid#642690/initial] (4) RewriteCond: input='GET /paul/index.html HTTP/1.1' pattern='paul' => matched
127.0.0.1 - - [23/Jul/2003:13:50:54 +0100] [localhost/sid#32b5b8][rid#642690/initial] (2) rewrite /paul/index.html -> /paul/index.html
127.0.0.1 - - [23/Jul/2003:13:50:54 +0100] [localhost/sid#32b5b8][rid#642690/initial] (2) local path result: /paul/index.html
127.0.0.1 - - [23/Jul/2003:13:50:54 +0100] [localhost/sid#32b5b8][rid#643cf0/initial/redir#1] (2) init rewrite engine with requested uri /error/HTTP_BAD_REQUEST.html.var

So I am rewriting /paul/index.html which works fine to exactly the same /paul/index.html which falls over and generates a bad request.

If anyone can spot what I am doing wrong I would be so very grateful.

 

grifter




msg:1520190
 2:49 pm on Jul 23, 2003 (gmt 0)

A quick guess. This line:

127.0.0.1 - - [23/Jul/2003:13:50:54 +0100] [localhost/sid#32b5b8][rid#642690/initial] (2) rewrite /paul/index.html -> /paul/index.html

I'm not sure, but will rewriting to /paul/index.html (the same URL) just kick off the rewrite engine over and over indefinitely?

deckchirboy




msg:1520191
 3:13 pm on Jul 23, 2003 (gmt 0)

Thanks Grifter, but no, you would need to force this with an [N] flag to reapply the rules.

The same thing happens regardless of the input url as long as it contains the word paul, eg localhost/paul is a fool/idiot.html

Storyteller




msg:1520192
 3:25 pm on Jul 23, 2003 (gmt 0)

deckchirboy, you should have your document root path prepended to the final resolved path, with appropriate message going in rewrite.log Why this isn't happening, I don't exactly know. In which section of httpd.conf have you placed your mod_rewrite directives: server config or virutal host?

deckchirboy




msg:1520193
 4:35 pm on Jul 23, 2003 (gmt 0)

Hi Story,

The rewrite rule is in the main section and doc root is set correctly here is the relevant part of /server-info:-

Server Version: Apache/2.0.39 (Win32)
Server Built: Jun 17 2002 23:16:55
API Version: 20020612:1
Hostname/port: localhost:80
Timeouts: connection: 300 keep-alive: 300
MPM Name: WinNT
MPM Information: Max Daemons: 64 Threaded: yes Forked: no
Server Root: C:/Server/Apache2
Config File: conf/httpd.conf

Module Name: mod_rewrite.c
Content handlers: yes
Configuration Phase Participation: Create Directory Config, Merge Directory Configs, Create Server Config, Merge Server Configs
Request Phase Participation: Translate Path, Check Type, Fixups
Module Directives:
RewriteEngine - On or Off to enable or disable (default) the whole rewriting engine
RewriteOptions - List of option strings to set
RewriteBase - the base URL of the per-directory context
RewriteCond - an input string and a to be applied regexp-pattern
RewriteRule - an URL-applied regexp-pattern and a substitution URL
RewriteMap - a mapname and a filename
RewriteLock - the filename of a lockfile used for inter-process synchronization
RewriteLog - the filename of the rewriting logfile
RewriteLogLevel - the level of the rewriting logfile verbosity (0=none, 1=std, .., 9=max)
Current Configuration:
RewriteEngine on
RewriteLog "C:/Server/Apache2/logs/rewrite.log"
RewriteLogLevel 9
RewriteCond %{THE_REQUEST} paul
RewriteRule paul c:/server/htdocs/paul/index.html [L]

As you can see I changed the rule to recognise and replace the name eric and to prepend the doc root manually and then the document root was added again by the system

Here is the log file

127.0.0.1 - - [23/Jul/2003:17:30:14 +0100] [localhost/sid#32b5b8][rid#642690/initial] (2) init rewrite engine with requested uri /eric
127.0.0.1 - - [23/Jul/2003:17:30:14 +0100] [localhost/sid#32b5b8][rid#642690/initial] (3) applying pattern 'eric' to uri '/eric'
127.0.0.1 - - [23/Jul/2003:17:30:14 +0100] [localhost/sid#32b5b8][rid#642690/initial] (4) RewriteCond: input='GET /eric HTTP/1.1' pattern='eric' => matched
127.0.0.1 - - [23/Jul/2003:17:30:14 +0100] [localhost/sid#32b5b8][rid#642690/initial] (2) rewrite /eric -> c:/server/htdocs/paul/index.html
127.0.0.1 - - [23/Jul/2003:17:30:14 +0100] [localhost/sid#32b5b8][rid#642690/initial] (2) local path result: c:/server/htdocs/paul/index.html
127.0.0.1 - - [23/Jul/2003:17:30:14 +0100] [localhost/sid#32b5b8][rid#642690/initial] (2) prefixed with document_root to C:/Server/Apache2/htdocsc:/server/htdocs/paul/index.html
127.0.0.1 - - [23/Jul/2003:17:30:14 +0100] [localhost/sid#32b5b8][rid#642690/initial] (1) go-ahead with C:/Server/Apache2/htdocsc:/server/htdocs/paul/index.html [OK]

I am becoming very frustrated so if you can help further please please do so.

figment88




msg:1520194
 4:59 pm on Jul 23, 2003 (gmt 0)

I'm by no means an expert on this but I think you should add in a RewriteBase directive after turning on the engine such as:

RewriteEngine on
RewriteBase /

deckchirboy




msg:1520195
 5:39 pm on Jul 23, 2003 (gmt 0)

err I think thats for per directory rewrites but thanks

deckchirboy




msg:1520196
 10:19 am on Jul 24, 2003 (gmt 0)

Resorted to upgrading Apache to version 2.0.47 and now it works.

So if anyone reading this is trying to get mod rewrite working with apache win32 and your version is less than 2.0.47 then you know what to do!

Thanks for the help

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved