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', 'Ahttp://www.googel.fi.*$' => 'q', 'Ahttp://.*search.msn.co.*results.*$'

'Ahttp://.*\.mysearch.com/jsp/GGmain.j sp?searchfor=.*$' => 'searchfor',

'Ahttp://search.freeserve.com/.*$' =>

'Ahttp://search.yahoo.com.*$' => 'va', 'Ahttp://search.yahoo.com.*$' => 'p', 'Ahttp://www.bbc.co.uk/cgi-bin/search/.*' => 'q',

'Ahttp://www.tiscali.co.uk/search/resu lts.php.*$' => 'query',

'Ahttp://www.altavista.com/web/results

'Ahttp://search.hotbot.co.uk/cgi-bin/pursuit.*$' => 'query',

'Ahttp://www.excite.co.uk/search/web/r esults.*$' => 'q',

'Ahttp://uk.search.yahoo.com/search.*$

$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 Basics

SEO Basics

Increase Your Profitability Through Powerful SEO Secrets. Search Engine Optimization SEO Strategy is the Most Effective Means by Which You Can Get More Quality Visitors to Your Website in Order to Successfully Improve Sales and Expand Your Customer Base.

Get My Free Ebook


Post a comment