http://www.onlinesales.co.uk - Testing Your Way To Success OnlineOnline Sales

UK Conversion & Search Optimisation Services

Bookmarklet To Trim Google Search URL

Matt Cutts, Google’s head of the webspam team, answered Which search feature would you add to Google? in the following Google Webmaster Central video.

In it he said he’d like to make the URLs cleaner, leaving just the search?q=whatever parts. He mentioned writing a Greasemonkey script, so I thought I’d write a little bookmarklet to help him out.

Just drag the following link to your bookmark bar and when you’ve completed a search in Google it will open a new window with the corrected search string and replace the URL.

javascript:(function(){var queryString=window.location.search.substring(1);var domainName=window.location.hostname;var myPathname=window.location.pathname;var searchArray=queryString.split('\&');var mySearch='';for(myElement in searchArray){if(searchArray[myElement].match(/^q=/)){var mySearch = searchArray[myElement];}}var searchOnly='http://'+domainName+myPathname+'?'+mySearch;with(window.open()){self.location.href=searchOnly;document.close();}})()

Trim Google URL

Edit – Thanks to a comment by Bruno Sabot I’ve updated the bookmarklet to work with iGoogle.

Edit 2 – I’ve changed the way I grab the query string and now the bookmarklet seems to work okay in most flavours of the main Google search.

Edit 3 – See Trim Google Search URL – Now with Added Hash! for a version which handles the form of the Google URL with (or without) hashes.

"Bookmarklet To Trim Google Search URL" was published on November 29th, 2009 and is listed in Search Engine Optimisation.

Follow comments via the RSS Feed | Leave a comment | Trackback URL

Comments on "Bookmarklet To Trim Google Search URL": 8 Comments

  1. Louis Halpern wrote,

    I wonder how many people email the the URL of the Google search result rather than one of the results?

    I think it’s a trend more prevalent with SEO’s rather than the mainstream public. I could be wrong.

  2. Bruno wrote,

    This bookmarklet do not work when you have this kind of URL (q= appear 3 times) :
    http://www.google.com/search?source=ig&hl=en&rlz=&q=google&aq=f&oq=&aqi=g-p3g7

    This one seems better :
    javascript:(function(){var windowLocationHref=window.location.href;var domainName=window.location.hostname;var myPathname=window.location.pathname;var searchArray=windowLocationHref.split(‘&’);var mySearch=”;for(myElement in searchArray){if(searchArray[myElement].match(/^q=/)){mySearch=searchArray[myElement];}}var searchOnly=domainName+myPathname+’?'+mySearch;self.location.href=’http://’+searchOnly;})();

  3. Online Sales wrote,

    Thanks for the comment Louis. I think you’re probably right, but it was a nice itch to scratch writing the bookmarklet.

  4. Online Sales wrote,

    Thanks for that Bruno. I seldom search using iGoole so didn’t think to test from there.

  5. Andy Beard wrote,

    This just breaks for me on the “q”s, though I tend to use the Google Global Plugin by Redfly more than anything else to clean up searches, so I can grab a local result with personalization off.

  6. Mike wrote,

    I find that I need to email Google search results a few times a month, and not for any SEO reasons. Usually when I do this I’m offering alternatives to people who are looking for a service or a product and are not familiar enough with Google to build the best search query, but I do it for other reasons too. While the format of the URLs never really bothered me, I can see why they would if you dealt with people internationally a lot. Good work.

  7. Online Sales wrote,

    Andy, could you email a search that breaks and I’ll fix the bookmarklet. The Redfly plugin is great but I spend more time in Chrome now and so developed some bookmarklets for similar functionality.

  8. Trim Google Search URL – Now with Added Hash! | Online Sales wrote,

    [...] getting the hash variation of the Google results URL here’s another update to the original Bookmarklet To Trim Google Search URL to also handle the “#” variation of Google [...]

Leave Your Comment