Forum Moderators: coopster

Message Too Old, No Replies

redirecting visitor from a particular site

         

JohnHeart

11:21 am on May 6, 2004 (gmt 0)

10+ Year Member



How do I redirect a visitor coming from a particular site?

For example visitor coming from:
- www.1-place.com redirect to www.mydomain/page-1.htm
- www.2-place.com redirect to www.mydomain/page-2.htm
- ...and so on

Is there an html code for that that I can write only on 1 page?

Thanks.

JohnHeart

korkus2000

6:32 pm on May 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey JohnHeart welcome to the a board.

You will have to use either js or serverside scripting for this. I would recommend serverside script since it will fire no matter what browser is viewing the site. Do you have access to PHP or ASP?

Marshall

6:47 pm on May 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You can use a metta tag:
<meta http-equiv="Refresh" content="10; URL=http://www.whatever.htm">

Content represents the number of seconds before the page redirects.

korkus2000

6:54 pm on May 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you want just a redirect or a redirect based on the referrer?

JohnHeart

6:59 pm on May 6, 2004 (gmt 0)

10+ Year Member



Yes. I have access to PHP. Im on Westhost server too.

I want a redirect based on the referrer.

Thanks.

jatar_k

7:02 pm on May 6, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



well you can access the referer via

$_SERVER['HTTP_REFERER'] [ca.php.net]

though they are not always present. You can then compare the referer with a list of referers that need to be redirected and redirect them using header [ca.php.net]

JohnHeart

8:04 am on May 7, 2004 (gmt 0)

10+ Year Member



I'm sorry but I don't know PHP coding.

jatar_k

8:26 pm on May 7, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



do you have a list of referers that you want to redirect?

how/where are they stored?

JohnHeart

4:17 pm on May 8, 2004 (gmt 0)

10+ Year Member



I haven't yet but I have them in mind. I was thinking of putting it to the root directory and save it as *.txt file. Inside this file will be the lists of referrers like:

www.abc*.com
www.blahblah.com
www.ufks*.*

and all of them will be redirected to www.mydomain.com/forbidden.html

Is that possible, written once in just a simple code like the robots.txt which only needs user-agent and dissalow syntax?

Thanks.

JohnHeart

jatar_k

5:58 pm on May 8, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I can't think of anything that would be quite that simple.

but

you could have the script do somthing like

1. load domains from textfile into array
2. compare with the refere if available
3. redirect if needed

I do see the issue that if the referer file gets too long it could be a bit slow but it should be a fine approach.

StupidScript

4:55 pm on May 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's a pretty simple script to do the job. It can also be used to weed out spiders and whatnot.

<?php

#THIS ARRAY CAN BE IN A SEPARATE FILE AND INCLUDED
$badapples=array("www.abc*.com","www.blahblah.com","www.ufks*.*");

#GRAB THE REFERRER
$checkfruit=$_SERVER['HTTP_REFERER'];

#RUN THROUGH BADAPPLES AND SEE IF THEY'RE IN REFERRER
foreach ($badapples as $kick) {
if (eregi($kick,$checkfruit)) {
#IF FOUND, KICK 'EM OVER TO THE NAUGHTY PAGE
header("Location: www.mydomain.com/forbidden.html");
}
}
?>

Have fun!

[edited by: jatar_k at 4:57 pm (utc) on May 11, 2004]
[edit reason] member request [/edit]

StupidScript

4:59 pm on May 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Note that this MUST come before anything else on any page you want it activated for. If there is ANY output before this, even so much as a space, then the "header" directive will not function.

This is true any time you use the "header" directive.

StupidScript

5:08 pm on May 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry..one last edit.

#RUN THROUGH BADAPPLES AND SEE IF THEY'RE IN REFERRER
foreach ($badapples as $kick) {
if (eregi($kick,$checkfruit)) {
#IF FOUND, KICK 'EM OVER TO THE NAUGHTY PAGE
header("Location: www.mydomain.com/forbidden.html");

#ADD AN EXIT STATEMENT TO STOP RUNNING THROUGH THE ARRAY
exit;

}
}