PDA

View Full Version : Webstats for dynamic pages


quadrant6
11-07-2006, 08:07 PM
I have a site containing the following pages:

item-list.php A list of categories & products

item-details.php Details for the selected product

Pretty standard really, MySQL is behind the scenes holding the data for all products. When you click on an item from item-list.php, the URL will be along the lines of:

item-details.php?item=TOQ (passes unique item code)

My problem is that in the webstats, instead of showing each url that gets hit like this, it simply shows tons of hits on item-details.php so we have no indication of which products are getting hit most.

Of course, I could have a separate file for each product but that would sort of defeat the purpose of using a database. Does anyone have any suggestions?

mark87
11-07-2006, 08:53 PM
Hum, .htaccess maybe (I don't know if it'd work with your stats or not but I think it probably would)?

You could use mod_rewrite eg.

RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^item\=([^&]+)$
RewriteRule ^$ /items/%1.html [R=301,L]

That would make your urls like (I think; you may need to play with it though!):

yoursite.com/items/ITEMID.html

quadrant6
11-08-2006, 08:34 PM
Thanks, I couldn't get that to work but this seems to:

RewriteEngine on
RewriteBase /
RewriteRule ^item-details.-(.*).htm$ item-details..php?item=$1 [L]



But I think I've misunderstood.. I thought it would be possible to implement these rules and not have to change any of the actual pages themselves but essentially, all the examples I've seen take the readable/friendly URL and turn it into (invisible or visible to user) the actual dynamic URL... i.e the above will:

when it sees.. item-details-TOQ.htm

actually fetch.. item-details.php?category=TOQ


But this means I have to change all my links on the site to the .htm format. I guess this is ok but I thought there was a way to do it the other way around.. (when it sees the dynamic url, turn it into firendly format)

mark87
11-08-2006, 09:13 PM
Oh, I'm not too sure as I don't use .htaccess in that way myself.

Perhaps someone else will be able to shed more light on how to do it whilst not changing links. :)