homepage Welcome to WebmasterWorld Guest from 54.237.54.83
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

    
Complex mod_rewrite problem
any assistance gratefully received
John_Caius




msg:1523209
 3:47 pm on Jan 7, 2003 (gmt 0)

Question from our software designer:

---

I'm using mod_rewrite to route URLs to a module done as a Location:

LoadModule BoldRetina_module modules/mod_BoldRetina.so

<Location /BoldRetina >
SetHandler mod_boldretina-handler
</Location>

RewriteEngine On

ReWriteLog c:\rewrite.log.txt
ReWriteLogLevel 9

# now the rewriting rules

# Root directory is mapped to ShowUI?UI=Home
# So incoming: www.mydomain.com/ becomes
www.mydomain.com/BoldRetina/ShowUI?UI=Home

RewriteRule ^/$ /BoldRetina/ShowUI\?UI=Home [L]

I don't want this to be a redirect that the browser sees, so I'm not
using R=301

The problem....

In my log file I get:

192.168.0.1 - - [07/Jan/2003:14:55:02 +0000]
[bryan/sid#23bd68][rid#472f30/initial] (2) init rewrite engine with
requested uri /
192.168.0.1 - - [07/Jan/2003:14:55:02 +0000]
[bryan/sid#23bd68][rid#472f30/initial] (3) applying pattern '^/$' to uri
'/'
192.168.0.1 - - [07/Jan/2003:14:55:02 +0000]
[bryan/sid#23bd68][rid#472f30/initial] (2) rewrite / ->
/BoldRetina/ShowUI?UI=Home

# I want it to stop here, but it does two more steps....

192.168.0.1 - - [07/Jan/2003:14:55:02 +0000]
[bryan/sid#23bd68][rid#472f30/initial] (3) split
uri=/BoldRetina/ShowUI?UI=Home -> uri=/BoldRetina/ShowUI, args=UI=Home
192.168.0.1 - - [07/Jan/2003:14:55:02 +0000]
[bryan/sid#23bd68][rid#472f30/initial] (2) local path result:
/BoldRetina/ShowUI

How can I stop it splitting the query string out into the args string?
The module I'm using requires the query string to be part of the URL.

---

Can anyone suggest what we can do to address this issue? Thanks. :)

 

andreasfriedrich




msg:1523210
 4:56 pm on Jan 7, 2003 (gmt 0)

The query string is still there after the rewriting is done.

Given a RewriteRule

RewriteRule /acarter /index.php?para=acarter

and a php script like

<?php echo $_SERVER['QUERY_STRING'];?>

you get

para=acarter

when /acarter is requested. Yet the RewriteLog still shows

init rewrite engine with requested uri /acarter 
applying pattern '/acarter' to uri '/acarter'
rewrite /acarter -> /index.php?para=acarter
split uri=/index.php?para=acarter
-> uri=/index.php, args=para=acarter
local path result: /index.php
prefixed with document_root to /var/www/html/index.php
go-ahead with /var/www/html/index.php [OK]

The splitting is only necessary to continue any matching. If it mod_rewrite did not strip off the query string from the end of the URI then a rule like this would not work:

RewriteRule /index.php$ /do_whatever

Since index.php would end with index.php?para=acarter.

Your module should be able to retrieve the query string from the query field of the uri_components record. This record may be accessed via the parsed_uri field of every incoming request.

Andreas

TwinkleToes




msg:1523211
 5:07 pm on Jan 7, 2003 (gmt 0)

Hi guys,

I'm John's software designer. The module is written in Delphi, and I don't have the source...

Interestingly, if I specify a 301 redirect, it works ok, although the user's browser sees the internal path. If I don't it doesn't work - I get a 404.

Could this be something to do with the ordering of Apache url flow? In that the module Location isn't being used after mod_rewrite. Should the modules be declared in any particular order?

Bryan

andreasfriedrich




msg:1523212
 5:24 pm on Jan 7, 2003 (gmt 0)

Welcome to WebmasterWorld [webmasterworld.com] Bryan.

Be sure to read Marcia`s WebmasterWorld Welcome and Guide to the Basics [webmasterworld.com] post.

Could this be something to do with the ordering of Apache url flow? In that the module Location isn't being used after mod_rewrite. Should the modules be declared in any particular order?

Try changing the order of the AddModule (mod_rewrite.c¦your_module) directives in httpd.conf.

Interestingly, if I specify a 301 redirect, it works ok, although the user's browser sees the internal path.

It works since mod_rewrite does not do anything on the second request.

Andreas

TwinkleToes




msg:1523213
 5:51 pm on Jan 7, 2003 (gmt 0)

Tell a lie, I get a 400 error - Bad Request.

Is there a way to get apache to tell me why it failed?

Bryan

andreasfriedrich




msg:1523214
 5:57 pm on Jan 7, 2003 (gmt 0)

The error log?

Set error reporting to the highest possible level.

Andreas

TwinkleToes




msg:1523215
 6:07 pm on Jan 7, 2003 (gmt 0)

Set the logging level to debug.

All I get is
192.168.0.1 - - [07/Jan/2003:18:06:29 +0000] "GET / HTTP/1.1" 400 290
in the access.log

and nothing at all in the error.log

John_Caius




msg:1523216
 10:26 am on Jan 10, 2003 (gmt 0)

bump - any other input on this gratefully received...

TwinkleToes




msg:1523217
 3:59 pm on Jan 10, 2003 (gmt 0)

Solved it.

I have to use the [PT] flag as it's being passed on to another module. doh!

Bryan

andreasfriedrich




msg:1523218
 1:47 am on Jan 11, 2003 (gmt 0)

Glad you got it to work Bryan.

I considered suggesting the [PT] flag but then thought that your module probably is a content handler and not another module called from the URI-translation hook.

Andreas

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