Forum Moderators: phranque

Message Too Old, No Replies

Redirecting From Based On Referrer

How should I go about redirecting

         

ScorpioJay

6:34 pm on Sep 7, 2003 (gmt 0)

10+ Year Member




Hi, I have a lot of websites that remain static. I have links on all of these pages to another page, however, I now want to change where those links take my visitors based on what page they are coming from.

How should I go about redirecting traffic if it comes from page a.html and redirecting traffic to another page if it comes from page b.html? (Redirection based on referrer)

Hope this makes sense, and I hope even more that someone can help me. Thanks,

Jay

jatar_k

7:30 pm on Sep 7, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld ScorpioJay,

What scripting languages are available to you? Any preferences?

It shouldn't be too difficult. You just need to make some kind of redirection script that knows where to send them based on where they came from.

Other than that you could also create a little script that writes the proper url into the page based on what page they are on.

Either solution wouldn't be overly difficult though it depends on what scripting language you have and if you are at all familiar with it. ;)

ScorpioJay

7:57 pm on Sep 7, 2003 (gmt 0)

10+ Year Member



I'd like to keep it with either JavaScript or using .htaccess, I've got a bit of familiarity with both, but I haven't really mastered either...

jdMorgan

8:21 pm on Sep 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just be aware that many visitors may not provide *any* referrer. Your design must be robust enough to handle this situation.

Users behind corporate firewalls/proxies, and those running Norton Internet Security and similar products will supply only a blank referrer.

Jim

ScorpioJay

8:44 pm on Sep 7, 2003 (gmt 0)

10+ Year Member



Would it be possible to incorporate a redirect to another webpage if there was no referrer too? How should this be done?

- Jay

ScorpioJay

1:47 am on Sep 8, 2003 (gmt 0)

10+ Year Member



This is what I've been told to use, however, it doesn't seem to be working right. Is there something wrong with the coding?

<SCRIPT LANGUAGE="JavaScript">

var refarray = new Array();
refarray['excite.com'] = "page.html?from=excite";
refarray['yahoo.com'] = "page.html?from=yahoo";
refarray['lycos.com'] = "page.html?from=lycos";
refarray['infoseek.com'] = "page.html?from=infoseek";
for (var i in refarray) {
if (document.referrer.indexOf(i)!= -1) window.location.replace(refarray[i]);
}
// End -->
</script>