Forum Moderators: phranque

Message Too Old, No Replies

two get request instead of one

mod rewrite, get

         

netfast_nl

7:51 pm on Dec 19, 2007 (gmt 0)

10+ Year Member



Hi all,

I am writing a gallery script that has stats in it. Everything works well untill I tested the stats (every pageview should write 1 stats record to the database)
But when I checked 2 records were being written! I checked the whole code for hours, but could find a wrong query responseble for that... I checked the logs and there was the answer!
Mod rewrite is causing the second call to the page...! If I call the page without mod rewrite only one record is added.

So something is not wright, but I'm stuck...

Does anybody have any clue?
I'm getting desperate!

Development specs:
Apache2
windowsXP SP2
PHP5.x
mysql 5.x

My .htacces file:
RewriteEngine on
ReWriteRule ^p(.*)/c(.*)/t(.*)/g(.*)/(.*)-(.*)/$ gallery.php?pagenum=$1&cid=$2&tid=$3&gid=$4&pnum=$5&pmax=$6 [L]

From the logs --> through calling gallery.php:
127.0.0.1 - - [19/Dec/2007:20:14:40 +0100] "GET /mfgs/gallery.php?pagenum=&cid=&tid=1&gid=12&pnum=1&pmax=1 HTTP/1.1" 200 6263
127.0.0.1 - - [19/Dec/2007:20:14:40 +0100] "GET /mfgs/content/2/2/12/achtergrond_tjolk.jpg HTTP/1.1" 304 -
127.0.0.1 - - [19/Dec/2007:20:14:40 +0100] "GET /mfgs/banners/120x600.gif HTTP/1.1" 304 -
127.0.0.1 - - [19/Dec/2007:20:14:40 +0100] "GET /mfgs/css/menustyle.css HTTP/1.1" 304 -
127.0.0.1 - - [19/Dec/2007:20:14:40 +0100] "GET /mfgs/css/frame.css HTTP/1.1" 304 -
127.0.0.1 - - [19/Dec/2007:20:14:40 +0100] "GET /mfgs/i/menu_back_first.gif HTTP/1.1" 304 -
127.0.0.1 - - [19/Dec/2007:20:14:40 +0100] "GET /mfgs/i/menu_back.gif HTTP/1.1" 304 -
127.0.0.1 - - [19/Dec/2007:20:14:40 +0100] "GET /mfgs/i/menu_back_over_selected.gif HTTP/1.1" 304 -
127.0.0.1 - - [19/Dec/2007:20:14:40 +0100] "GET /mfgs/i/menu_back_last.gif HTTP/1.1" 304 -
127.0.0.1 - - [19/Dec/2007:20:14:40 +0100] "GET /mfgs/i/star.gif HTTP/1.1" 304 -
127.0.0.1 - - [19/Dec/2007:20:14:40 +0100] "GET /mfgs/ HTTP/1.1" 200 20276

from the logs --> through using the mod rewrite way:
127.0.0.1 - - [19/Dec/2007:20:22:24 +0100] "GET /mfgs/p/c/t/g10/ HTTP/1.1" 200 7740
127.0.0.1 - - [19/Dec/2007:20:22:24 +0100] "GET /mfgs/css/menustyle.css HTTP/1.1" 200 1442
127.0.0.1 - - [19/Dec/2007:20:22:24 +0100] "GET /mfgs/css/frame.css HTTP/1.1" 200 2643
127.0.0.1 - - [19/Dec/2007:20:22:24 +0100] "GET /mfgs/content/2/2/10/schot1_tn2.jpg HTTP/1.1" 200 4244
127.0.0.1 - - [19/Dec/2007:20:22:24 +0100] "GET /mfgs/content/2/2/10/schot3_tn2.jpg HTTP/1.1" 200 3989
127.0.0.1 - - [19/Dec/2007:20:22:24 +0100] "GET /mfgs/banners/120x600.gif HTTP/1.1" 200 47637
127.0.0.1 - - [19/Dec/2007:20:22:24 +0100] "GET /mfgs/content/2/2/10/verdedigen_tn2.jpg HTTP/1.1" 200 3430
127.0.0.1 - - [19/Dec/2007:20:22:24 +0100] "GET /mfgs/content/2/2/10/shot2_tn2.jpg HTTP/1.1" 200 4082
127.0.0.1 - - [19/Dec/2007:20:22:24 +0100] "GET /mfgs/i/star.gif HTTP/1.1" 200 1002
127.0.0.1 - - [19/Dec/2007:20:22:24 +0100] "GET /mfgs/i/menu_back_over_selected.gif HTTP/1.1" 200 150
127.0.0.1 - - [19/Dec/2007:20:22:24 +0100] "GET /mfgs/i/menu_back.gif HTTP/1.1" 200 53
127.0.0.1 - - [19/Dec/2007:20:22:24 +0100] "GET /mfgs/i/menu_back_last.gif HTTP/1.1" 200 130
127.0.0.1 - - [19/Dec/2007:20:22:24 +0100] "GET /mfgs/p/c/t/g10/ HTTP/1.1" 200 7740
127.0.0.1 - - [19/Dec/2007:20:22:24 +0100] "GET /mfgs/ HTTP/1.1" 200 20276

netfast_nl

8:15 pm on Dec 19, 2007 (gmt 0)

10+ Year Member



Somebody said that it had to do with the (.*) in the rewriterule so I changed it to

ReWriteRule ^p([0-9]*)/c([0-9]*)/t([0-9]*)/g([0-9]*)/([0-9]*)-([0-9]*)/$ gallery.php?pagenum=$1&cid=$2&tid=$3&gid=$4&pnum=$5&pmax=$6 [L]

(0 or more numbers)
But that didn't solve the problem...

netfast_nl

8:29 pm on Dec 19, 2007 (gmt 0)

10+ Year Member



Also... Tried the whole script on my FreeBSD server and it has the same problem.
So windows is ruled out...

I can only think of an error in my htaccess file... But I don't see it :(

netfast_nl

8:07 am on Dec 20, 2007 (gmt 0)

10+ Year Member



I figured it out! :)

It appeared that there was an img tag with a src=""
That caused the extra GET request!

Filled the src="" with an image and the problem was fixed!

jdMorgan

6:13 pm on Dec 20, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad you got it sorted. I didn't see anything fatally wrong with your rule. I was going to suggest an improved-efficiency pattern, but this would not have fixed your problem:

RewriteRule ^p([[^/]+)/c([^/]+)/t([^/]+)/g([^/]+)/([^\-]+)-([^/]+)/$ gallery.php?pagenum=$1&cid=$2&tid=$3&gid=$4&pnum=$5&pmax=$6 [L]

Here, we define the character that should end each subpattern, and we require at least one character in each subpattern.

Jim