Forum Moderators: phranque

Message Too Old, No Replies

yet another rewrite problem

it used to work, now it doesn't. What changed?

         

js1063

2:07 am on Sep 14, 2005 (gmt 0)

10+ Year Member



Hi all:

Occasionally, our HTML folks will get lazy and forget to prepend the correct directory to some links. So, they might say something like "foo.html" when they really mean to say "/html/foo.html" (or whatever). In order to get around this, I have two fairly simple rewrite rules:

RewriteRule ^/cgi/(.*)\.html$ http://www.example.com/html/$1.html [L]
RewriteRule ^/cgi/(.*)\.gif$ http://www.example.com/images/$1.gif [L]

This is supposed to catch any links which look like they should be pointing at the html or images directories and point them there. Up until recently, it was working. (We recently changed platforms from Solaris/Stronghold running I-don't-know what version of Apache to linux/apache-1.3.33 with mod/ssl and mod/perl)

When I turn on the rewrite log and jack up the log level as far as it will go (to 9), I see:

172.**.1.76 - - [13/Sep/2005:19:02:18 -0700] [www.example.com/sid#8e9905c][rid#90371d4/initial] (2) init rewrite engine with requested uri /cgi/hearingdd.html
172.**.1.76 - - [13/Sep/2005:19:02:18 -0700] [www.example.com/sid#8e9905c][rid#90371d4/initial] (3) applying pattern '^/cgi/(.*)\.html$' to uri '/cgi/hearingdd.html'
172.**.1.76 - - [13/Sep/2005:19:02:18 -0700] [www.example.com/sid#8e9905c][rid#90371d4/initial] (2) rewrite /cgi/hearingdd.html -> http://www.example.com/html/.html
172.**.1.76 - - [13/Sep/2005:19:02:18 -0700] [www.example.com/sid#8e9905c][rid#90371d4/initial] (3) reduce http://www.example.com/html/.html -> /html/.html
172.**.1.76 - - [13/Sep/2005:19:02:18 -0700] [www.example.com/sid#8e9905c][rid#90371d4/initial] (2) local path result: /html/.html
172.**.1.76 - - [13/Sep/2005:19:02:18 -0700] [www.example.com/sid#8e9905c][rid#90371d4/initial] (2) prefixed with document_root to /home/webby/example/html/.html
172.**.1.76 - - [13/Sep/2005:19:02:18 -0700] [www.example.com/sid#8e9905c][rid#90371d4/initial] (1) go-ahead with /home/webby/example/html/.html [OK]
[Tue Sep 13 19:02:18 2005] [error] [client 172.**.1.76] client denied by server configuration: /home/webby/example/html/.html

So, for whatever reason, the pattern is matching (see the third line of the rewrite log) but $1 isn't getting populated (or something). I tried using $0 on the outside chance that someone got cute and changed the indices for the pattern matches, but... no go.

This is not a big deal but it's driving me crazy. As regular expressions go, these are not very complicated. Any help will be appreciated. Thanks!

jarom

[edited by: jdMorgan at 4:17 am (utc) on Sep. 14, 2005]
[edit reason] Obscured specifics per TOS. [/edit]

jd01

5:57 pm on Sep 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Fascinating... no guess, but I'll give it a bump.

Justin

js1063

6:13 pm on Sep 14, 2005 (gmt 0)

10+ Year Member



Hi all:

I continue to puzzle over this. I am thinking that maybe something is wrong with my regexp library or something because this makes no sense at all.

Just for grins I have added a "test" rule which is:

RewriteRule ^/jarom/(.*) 0=$0,1=$1,2=$2,3=$3 [L]

This should basically take anything starting with /jarom/ and show me what it's doing with the regular expressions. When I run this on a bogus URL, I get the following types of entries in my log:

172.*.*.76 - - [14/Sep/2005:09:49:30 -0700] [www.example.com/sid#81fa05c][rid#831fe2c/initial] (2) init rewrite engine with requested uri /jarom/cgi/product.cgi
172.*.*1.76 - - [14/Sep/2005:09:49:30 -0700] [www.example.com/sid#81fa05c][rid#831fe2c/initial] (3) applying pattern '^/cgi/(.*)\.html$' to uri '/jarom/cgi/product.cgi'
172.*.*.76 - - [14/Sep/2005:09:49:30 -0700] [www.example.com/sid#81fa05c][rid#831fe2c/initial] (3) applying pattern '^/cgi/(.*)\.gif$' to uri '/jarom/cgi/product.cgi'
172.*.*1.76 - - [14/Sep/2005:09:49:30 -0700] [www.example.com/sid#81fa05c][rid#831fe2c/initial] (3) applying pattern '^/jarom/(.*)' to uri '/jarom/cgi/product.cgi'
172.*.*.76 - - [14/Sep/2005:09:49:30 -0700] [www.example.com/sid#81fa05c][rid#831fe2c/initial] (2) rewrite /jarom/cgi/product.cgi -> 0=/jarom/,1=,2=,3=
172.*.*.76 - - [14/Sep/2005:09:49:30 -0700] [gvlinux.goldviolin.com/sid#81fa05c][rid#831fe2c/initial] (2) local path result: 0=/jarom/,1=,2=,3=

As you can see from the 5th line of the log, the pattern is being correctly matched but the replacement strings are a little goofy. $0 gets filled in with "/jarom/" (is this normal behavior?) and $1, $2, etc. are blank.

Don't know if this helps anyone... I glanced through the code for mod_rewrite but it was more complicated than I wanted to delve into.