I have a script that I want to use for tracking purposes. What I would like to do is send all initial requests for pages (html, htm, php etc.) to my tracking script which will record details contained in the query string before redirecting them to the page that they initially requested. Subsequent requests from the same user (eg when clicking an internal link) should not be rewritten to avoid excessive processing.
Is this even possible and what would be the best way of going about it (sorry but mod_rewrite is totally new to me). I was thinking of using the HTTP referer to determine if it is the users initial request or not something like this:
# Do not rewrite these file types
RewriteRule \.(txt|gif|jpeg|jpg|png|css|ico|xml|xsl|pdf)$ - [L]
#Rewrite to tracking script
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.com/ [NC]
RewriteRule ^/?(.*)$ /tracking-script.php?url=$1 [NC, QSA]
I need to append the original query string to the rewritten url so that the tracking script has some data to work on and also need to add the originally requested url so that the script can redirect to the correct page.
Any help much appreciated.