Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite and referer tracking?

Another "How do I do this..."

         

Bangkok9

4:12 pm on Mar 9, 2004 (gmt 0)

10+ Year Member



Howdy, I hope one of the smart people around here can help me out with this.

I'm developing a site and don't have access to the .conf file nor do I have the option to use .shtml pages nor do I have the option to use cookies.

All I've got to work with is the .htaccess file.

The client's affiliates are sending traffic in via a link that looks like:

[clientsite.com?src=affiliatename...]

This does a fine job, and loads the client's index.html page. Happyville, so far.

Now, when the visitor surfs through the site to a second page, call it page2.html, I want to make the URL in the browser look like

[clientsite.com...]

I know that I'll need...

RewriteCond %{HTTP_REFERER}!^.*?src=.*$ [NC]
RewriteRule ^(.*)$ $1?src=none [L]

... in order to append in cases where the URL is typed in, i.e. no refering link.

BUT, then what?

I thought first about doing...

RewriteCond %{HTTP_REFERER} ^.*?src=.*$ [NC]
RewriteRule ^(.*)$ $1?%{HTTP_REFERER} [L]
RewriteRule ^(.*)\?.*\?(.*)$ $1?$2

... but it didn't seem to work.

I don't know if my syntax is bad, if you can't use an environment variable in that context or if this sort of chaining is illegal.

Can anyone put me straight on this? I'd be much obliged.

stevenmusumeche

10:47 pm on Mar 9, 2004 (gmt 0)

10+ Year Member



AFAIK, mod_rewrite is not meant to do that. You'd need to rewrite every href in the page. You're better off setting a session variable or cookie.

merrioc

2:15 am on Mar 10, 2004 (gmt 0)

10+ Year Member



if you like I can show you a method in php thats rather simple as long as you can do includes.

Bangkok9

4:18 am on Mar 12, 2004 (gmt 0)

10+ Year Member



Well, thanks for the offers, but it's not really the help I was looking for.

We're not doing cookies at all nor shtml. And we're not going to php.

I'm still hoping for a solution from somebody.

closed

4:30 am on Mar 12, 2004 (gmt 0)

10+ Year Member



Well, you shouldn't be using HTTP_REFERER, because it isn't very reliable for what you're planning on doing. You should try using REQUEST_URI and/or QUERY_STRING.

jdMorgan

2:25 am on Mar 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Bangkok9,

Welcome to WebmasterWorld [webmasterworld.com]!

If you want the browser to show the affiliate in order to "carry" the affiliate info throughout the user's "session" then you'll need to use an external redirect:


RewriteCond %{HTTP_REFERER} \?src=(.*)$ [NC]
RewriteRule ^(.*)$ $1?src=%1 [R=301,L]

However, as noted above, referrers are notoriously unreliable, especially when the user connects through a caching proxy (e.g. AOL) or is using a firewall/security product such as Norton Internet Security -- Both of these will block the referer information.

Have you considered setting up wildcard subdomains? That would allow you to put the affiliate at the front end of the URL, and all of your internal site links would remain unchanged.

Jim