Search Engine Friendly Migration

The biggest pain for me, having just migrated from Geeklog to Drupal is that my site has a good index in google and other search engines. All those users finding my site on Google are suddenly getting the 404 error page, giving up, and going away when they could dig a bit deeper and find exactly what they were looking for.

So, I harnessed my experience writting HTTP_REFERER logging systems for geeklog to provide myself with a Page with PHP enabled content to parse the Search Engine query from the HTTP_REFERER and do a search on my Drupal site to try and find what the user was actualy looking for. I thought I'd share with the world, as that's the entire point of open source systems like Drupal.

$searchengines = array(

'Ahttp://www\.google.*$' => 'q', 'A*$' => 'q', 'Ahttp://.**results.*$'

'Ahttp://.*\ sp?searchfor=.*$' => 'searchfor',

'A*$' =>

'A*$' => 'va', 'A*$' => 'p', 'A*' => 'q',

'A lts.php.*$' => 'query',


'A*$' => 'query',

'A esults.*$' => 'q',


$referer = getenv("HTTP_REFERER"); while( list( $regexp, $qsitem ) = each(

echo( t("<br/><h2>Search Engine Detected</h2>It would appear you arrived here on the wings of a search engine, so, I will search my local database and show you anything that matches what you were looking for:<br/>"));

$url = parse_url( $referer ); $querystring = $url['query'];

$querystring = explode( "&", $querystring ); while( list( , $value ) = each( $querystring

$item[1] = urldecode( $item[1] ); echo ( search_data( $item[1] ) );

This provides a (partial) list of regular expressions for common search engines, with information as to which query string parameter is the query the user entered. The HTTP_REFERER value (the site the user clicked a link to get to your site) is then examined against this list. When a match is found, a search is done using the standard Drupal search call (search_data). This locates potential matches, and hopefuly, keeps the user on your site.

In order to use this, create a new node which allows PHP code. You can call it what you want, and put whatever explanatory text you like on it. You can set whatever path you like. Just drop the above code-clip into place. Then, in Administration -> Settings set the 404 handler to be the path to the new node you created, and voila, if the user arrives from a recognised search engine, their search is performed on your site. It's working nicely for me.

SEO Article Copywriting

SEO Article Copywriting

Ghost Writing and Its Link to Internet Marketing. From 1996 to 2000, SEO copywriting was still not formulated. To optimize Websites, operators and owners had just needed to formulate and create Meta tags or titles and submit the tags and the whole Website to directories and search engines so that search listing would include the Website.

Get My Free Ebook

Post a comment