This weekend, after spending some time drooling over most of Adrian Holovaty’s site (a site that’s run by a custom publishing system he wrote), I decided to buckle down and write a reliable search term highlighting system like the one kicking ass over in his world. (I got most of the way there on my own; Adrian was kind enough to help me get past the one major problem I found.) Now, visitors from Google will be greeted with both a custom header and all their search terms highlighted, as well as an option to use the engine here to perform their search. Check it out — follow this link to search Google for “incredible day,” and then click through the first return.


How hard was that to add to Movable Type, or was it added another way? PHP?

• Posted by: Mike on Nov 27, 2002, 9:26 AM

Mike, it’s written in PHP. I wrap all my pages in a PHP wrapper — hence the “/index.php?archives/001088.php” URL — which makes things a lot easier, since I can just put all the various PHP scripts for page transformation into that wrapper. In this case, that’s what I did.

Note that there appears to be a problem with the interaction between the script and Internet Explorer 5.0 for the Mac, and as of right now, I understand from a friend that the highlighting doesn’t happen in some cases. Specifically, it doesn’t happen when someone with IE5/Mac requests a page using one of my old Manila URLs — e.g., — because Apache redirects the browser to the real URL and IE5/Mac clears out the referrer information when that redirection happens. That means that once an IE5/Mac user ends up on the final page, that page has no clue that they started out from a Google search, and the highlighting stuff doesn’t get activated.

(It’s unclear to me which behavior is correct. So far, all other browsers that I’ve tested keep the Google referrer information through all the page redirections, and thus, the final page understands where the user started. IE5/Mac seems to be the outlier. Anyone find any others that don’t work?)

• Posted by: Jason on Nov 27, 2002, 3:08 PM

Nice job, Jason! Great stuff.

For what it’s worth, it worked for me in Moz 1.1 and IE 6, both on Windows. (But you probably knew that already. :-) )

• Posted by: Adrian on Nov 27, 2002, 11:06 PM

Well fuck me.

(Click through, do).

• Posted by: Dean on Nov 29, 2002, 2:16 PM

Awesome, both on the highlighting and the fact that you’re the first Google hit return for fuck me! When did you implement the search term highlighting, though?

• Posted by: Jason on Nov 29, 2002, 5:14 PM

Oh, just tonight. I couldn’t stand that you had it and I didn’t.

Okay, in truth I couldn’t stand Holovaty had thought of it first.

Yours is still not showing up in IE5 Mac. Is there any javascript in use there?

• Posted by: Dean on Nov 29, 2002, 5:53 PM

No, Dean, no JavaScript — it truly is that IE5/Mac does something that no other browser does, which is that it changes the Referer HTTP header as it gets redirected on a website. When you hit my site via one of the old Manila-style URLs, you get redirected (via Apache mod_rewrite magic) to the right page; IE5/Mac clears out the Google referrer URL from the HTTP header block when it ultimately requests the final page.

For an example of it working right, use this search, and then click on the second link (the one to my About page).

• Posted by: Jason on Nov 29, 2002, 5:57 PM

Ah, so it is a mod_rewrite thing.

Did you try bypassing the referrer and pulling $_SERVER[“QUERY_STRING”]?

• Posted by: Dean on Nov 29, 2002, 6:13 PM

I don’t have access to the query string; only Google had access to that puppy.

I’m thinking about having mod_rewrite set an environment variable to the original referrer when it sets a rewrite in motion, so that all subsequent redirects have access to it. I dunno if it’ll work, but it’s worth a try. (Although I don’t know how much work to put into fixing what appears to be a bug with a single browser…)

• Posted by: Jason on Dec 1, 2002, 6:44 PM
Please note that comments automatically close after 60 days; the comment spammers love to use the older, rarely-viewed pages to work their magic. If comments are closed and you want to let me know something, feel free to use the contact page!