Forum Moderators: coopster

Message Too Old, No Replies

How do I redirect someone from where they visit me from?

         

progex

7:41 pm on Jan 27, 2004 (gmt 0)

10+ Year Member



For example, if the visitor comes from the search term "widgets" in Google, how would I change the content on a page so that it targets the "widget" category.

Redirecting may be dangerous in terms of SEO, so is there a way to display dynamic content according to where the visitor comes from?

I've seen a particular site do this, however, the extension on the landing page is .html. If need be, I will sticky you the URL of the page so that you can see it in "detail".

jatar_k

9:42 pm on Jan 27, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Well, for starters, you can set up apache so that the html extension is parsed for php using htaccess or just httpd.conf using something like

addtype application/x-httpd-php .php .html

For the dynamic serving based on referer data you could analyze the referer using $_SERVER['HTTP_REFERER'] [ca.php.net] and then include content based on parsing the query string.

I use this piece for an apache log parser to chop up query strings. This catches most of the query strings and grabs out the keywords and increments a keyword array. This is pulled from a large script so it may have some unrelated vars in there but it does work quite well.

It does a ton of other stuff at the beginning but these lines are relevant

$line = fgets($fp)
$qusplit = split('"',$line);
$queryarr = parse_url($qusplit[3]);

these are used because it needs to get the referer from the logfile in your case it could be

$queryarr = parse_url($_SERVER['HTTP_REFERER']);

if (!empty($queryarr['query'])) { 
parse_str($queryarr['query'],$breakuparr);
if (isset($breakuparr['encquery'])) {
$qs = $breakuparr['encquery'];
} else if (isset($breakuparr['q'])) {
$qs = $breakuparr['q'];
} else if (isset($breakuparr['p'])) {
$qs = $breakuparr['p'];
} else if (isset($breakuparr['source']) && $breakuparr['source']!= "NSCPTop") {
$qs = $breakuparr['source'];
} else if (isset($breakuparr['query'])) {
$qs = $breakuparr['query'];
} else if (isset($breakuparr['Keywords'])) {
$qs = $breakuparr['Keywords'];
} else if (isset($breakuparr['cid']) && isset($breakuparr['s'])) {
$qs = $breakuparr['s'];
} else {
$qs = "";
}
// end query finding stuff
$qs = strtolower(trim($qs));
if (!empty($qs)) {
$qs = str_replace('\"','',$qs);
$qs = str_replace('+','',$qs);
}
}