Redirect Search Traffic to Own Search


I have a problem with a blog in that I lost a whole heap of posts. Many of these pages are still indexed though so I want to create redirects from these pages to relevant posts on my blog. I want to achieve this by grabbing what the visitor searched for (from the referrer) and then sending them to the results page of the search function on my blog for that exact term.

So basically I need to grab the search term from the referrer and then redirect the visitor to "[search_term].

As you have probably already worked out my php knowledge is pretty close to zero. I hope to achieve this by modifying the below code I found here - … our_Search

Can anyone please give me any suggestions on how to do this? Or even where/what I should start learning so I can work it out? Any help is greatly appreciated.

I am guessing I need to replace the line starting with " xarResponseRedirect" but I have no idea how to do this.

Many thanks in advance.

function lilina_userapi_redirect($args) { extract($args); if ((isset($_SERVER['HTTP_REFERER'])) and ($_SERVER['HTTP_REFERER'] != '')) { $keywords = ""; $url = urldecode($_SERVER['HTTP_REFERER']); // Google if (eregi("",$url)) { preg_match("'(?|&)q=(.*?)(&|$)'si", " $url ", $keywords); } // AllTheWeb if (eregi("www.alltheweb",$url)) { preg_match("'(?|&)q=(.*?)(&|$)'si", " $url ", $keywords); } // MSN if (eregi("search.msn",$url)) { preg_match("'(?|&)q=(.*?)(&|$)'si", " $url ", $keywords); } // Yahoo if ((eregi("",$url)) or (eregi("",$url))) { preg_match("'(?|&)p=(.*?)(&|$)'si", " $url ", $keywords); } // Looksmart if (eregi("",$url)) { preg_match("'(?|&)qt=(.*?)(&|$)'si", " $url ", $keywords); } if ((isset($keywords[2])) and ($keywords[2] != ' ')) { $keywords = preg_replace('/"|'/', '', $keywords[2]); // Remove quotes $keyword_array = preg_split("/[s,+.]+/",$keywords); // Create keyword array $keyword_array = array_unique($keyword_array); $redirect = implode(' ', $keyword_array); xarResponseRedirect(xarModURL('lilina', 'user', 'search', array('q' => $redirect))); } return; } }

Sponsor our Newsletter | Privacy Policy | Terms of Service