Jump to content

Redirect Search Traffic to Own Search


mcairns

Recommended Posts

Hi,

 

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 "http://myblog.com/search.php?[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 - http://wyome.com/docs/Redirect_Search_Engine_Traffic_to_your_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("www\.google",$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("yahoo\.com",$url)) or (eregi("search\.yahoo",$url))) {

               preg_match("'(\?|&)p=(.*?)(&|$)'si", " $url ", $keywords);

            }

            // Looksmart

            if (eregi("looksmart\.com",$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;

       }

    } 

 

Link to comment
Share on other sites

Thanks very much for the response.

 

These users will be coming from Google mainly.

 

So they will land on my blog with a referrer of something like:

 

http://www.google.com.au/search?hl=en&q=search+term&btnG=Google+Search&meta=

 

I then want to be able to redirect this user with this referrer to myblog.com/search.php?search+term

 

So, as an example, if someone searches for "disney land" in Google and clicks on a result for my blog, I want to then redirect them to myblog.com/search.php?disney+land

 

I hope this makes it clearer:)

Link to comment
Share on other sites

oh i understand what you are saying,

i've actually done something similar

to this before, except i didnt redirect them,

all i did was record the search terms,

you are going to need to do something like this:

 

<?php

// Enter Your Website URL below
$url = "http://www.myblog.com/search.php";

// Check The Refferer
$referer = $_SERVER['HTTP_REFERER'];
$blown = explode('/', $referer);
// Check if they are coming from Google
if($blown[2] == 'www.google.com'){
	$words = explode('q', $referer);
	$terms = explode('&', $words[1]);
	header("Location: ". $url . $terms[0]);
} else{
	// Put Your Content Here
	echo "Welcome To Me Website....";
}

?>

 

i didnt test this out yet,

but hopefully you see what

i am trying to do....

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.