« Previous | Next»

Seamless integration Google Search into Lifetype (Part 4)

Posted by coldtobi | 24 Aug, 2008, 15:35

Last but not least, I'll complete this how-to series.

Up-to-now we have prepared Lifetype to integrate google search as primary blog search engine.

For the ones just finding them on the last part, here is a list for the others:

_ASIP_

As noted before, this part finalizes the integration. If you read the requirements in part 1, you need support for ModReWrite.

ModRewrite will be used to add the missing parameters to the form, so that lifetype won't get upset when your reader searches through your blog.

For this, get the search term you found out in part 3 and open up your .htaccess. (Make sure that it it the one lifetype installation's base directory.)

Here's a copy of the relevant section, I'll use to explain how it works and what have to be changed to get it working on your site. (note: watch the line breaks! Should be 3 lines of code)

RewriteCond %{QUERY_STRING} ^.*(cx=partner-pub-.*)
RewriteCond %{QUERY_STRING} !.*op=Search&searchTerms=coldtobi.*
RewriteRule .* http://blog.coldtobi.de/index.php?%1&op=Search&searchTerms=coldtobi [QSA,L,NE]

How the snippet works:
As stated, the trick is to use these serveral rules to "rebuild" the URL. This is done with the Rules above, only using two Regular Expressions.

ReWriting is done in two stages:
(okay, that's very simplyfied, but the whole story is way beyond the scope of this howto.)
  1. Finding out, which URL to rewrite (The ReWriteConds)
  2. Changing the URL to its new content (ReWriteRule)

The first "RewriteCond" will makes sure, that the rules only catches the request we want to change by the search form by using some characterisitc parameters. It is important, that this parameter is not used anywhere else, as this might jeopadize other operations.
To make sure, I choosed to use the partner-id issued by google. (The partner-pub-....". So the first RewriteCond catches all Query-Strings which contains this id.)

The second RewriteCond make sure, that we won't apply the rules recursively. If you remove it, you'll get a pretty error message that the browser cannot complete the request. To understand this you have to know how the ReWriting is processed by the web server: After completing the rewriting, the request is "fed again" into the webserver as a new request. And this new request is then matched again against the Rules. You just created a nice loop, until your browser gives up. To avoid this from happening, we make use of what we do to the URL.

The third line rewrites the URL. This only takes place when the previous two rules where appliying. In this case, we add everything we need to fake a lifetype search.
This is done in this line: We take the query string from the above rules and assemble a new URL to be processed by Lifetype, simply adding
&op=Search&searchTerms=coldtobi after the original query.

Back to the second line, if any recursion occurs, we know it as exactly this string is present. So naturally the trick is to assemble a RexExp which matches everthing but this added part. This is exactly the purpose of the second line.

What to change

You have to add these lines to your .htaccess and then edit them. I suggest you put them on the top of your file, just to avoid that other rules interfere with these.

To outline, what to change, look at the above lines. The parts to change are red. This is actually the search term you found out in the last part. Just fill it in and it should work. If the search term contains any special characters, make sure to encode them accoringly: A "Space", for example should be written as "%20".

Please make sure, that the underlined parts in my exmpale must read excactly the same -- by the letter (of course, with your search term). If not, the ReWrite Rules won't work. 

If you web hosting company does not support the "QSA" method, try the "Forced Redirect": Subsitute the "[QSA,L,NE]" with "[R,L,NE]". However, this is visible to the outer world and therefore might be not as desireable.

Well, now it is supposed to work. Just make sure you upload everything and if you worked on a backup-template, you should not forget to switch to that template.

So, Enjoy your new search engine. (And hopefully lots of earnings with that!)

Tips and Tricks, Lifetype | Comments (10) | Trackbacks (0)

Related Articles:

10 Comments | "Seamless integration Google Search into Lifetype (Part 4)" »

  1. Nancy :

    06/11/2008, at 05:45 [ Reply ]

    Thank you for this insightful series. I just hope I will be able to put what you have taught is into proper practice.

    Having an integrated search engine within the pages of my site would help to get that professional image I am looking for. Thanks again.

  2. Odzyskiwanie Danych : Great tutorial

    01/12/2008, at 11:06 [ Reply ]

    Thanks for this great tutorial. I was to install lifeType but I read somewhere it isn't supported now. Is it truth?

  3. Tkaniny :

    16/12/2008, at 18:06 [ Reply ]

    Outstanding work! Thank you so much for taking your time to put this all up together. However from what I've heard, Odzyskiwanie Danych (what a weird name btw..)might be right. Can you confirm it is still being supported ? Thanks!

  4. coldtobi : Support

    20/12/2008, at 17:55 [ Reply ]

    Currently my DSL is not working, so I simply cannot check...
    But maybe you ask this question at the lifetype-forum?

  5. Brett Dugan :

    18/02/2009, at 08:24 [ Reply ]

    I am going to join the others and praise you for taking the time to put this series of tutorials together. I have tried numerous blogging platforms and lifetype looks to be my next project so thank you for this.

  6. Kolorowanki :

    07/07/2009, at 12:05 [ Reply ]

    I kinda don't like google search on blogs and websites in general. I had so many bad experience with it in the past (redirecting to the global results for google and so on) that I'd like to avoid it now.

  7. coldtobi : Re: Kolorowanki

    07/07/2009, at 16:59 [ Reply ]

    Well, a webmaster should care about that... This article is about custom search engines "CSE" With CSEs you have absolute control over which results should appear. You can tell google only two show results from e.g blog.coldtobi.de

    I'm also currently preparing an article showing how to telle google about what it should include into the CSE and what not. This way, you can concentrate on the articles, not on the archives ;-)

  8. Jump higher :

    28/02/2010, at 10:13 [ Reply ]

    I am creating a blog so I was limited to wordpress, lifetype, reblog, geeklog, serendipity and one other. However, I still find lifetype to be the best for my needs.
  9. reflective vest :

    26/06/2011, at 14:40 [ Reply ]

    Great tutorial. Honestly, the level of customization that google allows is crazy! I love it!

  10. loRdcyphon :

    27/07/2011, at 20:58 [ Reply ]

    Yes, really nice tutorial. Mod Rewrite is a really mighty tool, which is absoluteley useful. "You will hate it or you will love it" :-)

    Greez