6 May 2008

Ampersands in Query Strings, Begone!

Why hello there! Yes, I was off the blog radar for a little over a year. We'll chat about it sometime. (I've been microblogging on Twitter though. 's fun.)

Speaking of Twitter, John Gruber just pointed out "W3C's long-ignored suggestion to use ';' instead of '&' as [an] argument separator in URLs (because '&' causes so many problems when not escaped)."

It brought back memories of my first year at AT&T Bell Labs in 1995, when I tried to promote usage of semicolons. It never took hold. Third party design agencies pretty much laughed that recommendation right off the stage.

(Y'know ... I think the last time I was laughed at that much was when I gave a fifth grade presentation on the metric system. Grade schoolers can be so very cruel, I know.)

Anyway, John, this one's for you and all those with the audacity to hope for semicolons in their query strings.

# Replace ampersands in QS with semicolons
# Add as first two rules in .htaccess or httpd.conf

RewriteEngine On

RewriteCond %{QUERY_STRING} ^([^\&]+)\&(.+)$
RewriteRule ^(.+)$ $1?%1;%2 [E=amp:y,N]
RewriteCond %{ENV:amp} y
RewriteRule ^(.+)$ /$1 [R=permanent,NE]

For the uninitiated, here's how it works. First, the RewriteEngine must be On, so that's a given. Then we have two Rewrite Condition/Rule pairs.

The first pair looks for an ampersand in the query string. If found, we rewrite using a semicolon. (%1 and %2 refer back to the query string portions found before/after the ampersand.) We also set a variable "amp" to mark that we've encountered an ampersand, and then we repeat rule processing from the start (N).

For the second pair, what we're aiming for is a single permanent redirect (since we're swapping out one ampersand at a time). That's where the "amp" variable comes in. If it's set, we must have cleared the first Cond/Rule pair, so we now permanently redirect. No encoding (NE), please. That's it!

Consider it a first pass. I realize there are some boundary conditions I'm not taking care of yet, like leading and trailing ampersands in the QS, not to mention catching & amp; outright. (Mmm-hmm, ever try cutting-and-pasting a malformed link?)

Also, yes I know this blog presently uses ampersands ... and what about the server side? Will it treat those semicolons properly? (Can yours truly be redeemed, or has he painted himself into a corner? Stay tuned!)

For now, the above seems to work quite nicely on my Apache 2.x installation. Feedback most welcome. Don't be shy now.

Lest I forget, my sincere thanks to @gruber for singlehandedly waking me up from my over one year-long blogger hibernation. Let's see if I stay awake this time.

Update: I just noticed my last blog post also concerned query strings! Wow, what are the odds?

25 March 2007

Query String Removal Helpful?

Those of you in Search Engine Optimization circles have no doubt read the article about a recent Search Engine Watch Case Study ... or perhaps you read the article about the case study ... or the Digg comments about the article about the case study.

The case study, titled "Remapping Dynamic URLs to Static URLs can Increase Traffic", describes what happened when PlumberSurplus.com rewrote all the links on their site, in particular the sitewide removal of the query string (the part after the question mark).

For instance, this Bathroom Faucets link (and others like it):

http://www.plumbersurplus.com/category.aspx?Cat=991

Was rewritten and permanently redirected to:

http://www.plumbersurplus.com/Cat/Bathroom-Faucets/991

What happened next? "Within two months, rankings began to improve, and the number of indexed pages began to increase." Who-hoo!

I'm somewhat hesitant, however, to jump to conclusions about the query string removal (the "remapping of dynamic to static URLs") being the cause celebre here. Consider:

Note that Plumber Surplus did undertake other SEO activities during this timeframe, so it's hard to credit all the search engine ranking and indexing improvements to this change alone.

In fact, one of those changes is staring us right in the face ... and I say it was this other change, not the query string removal, that had the greater effect.

Continue reading "Query String Removal Helpful?" »

17 January 2007

Stephen Colbert Explains AT&T For You

A friend of mine (and fellow AT&T alumnus) summed this video up nicely: “I like that the audience thinks the chart is made-up comedy.”

Spot-on, fellow alum. Nothing could be further from the truth! Remember, Stephen Colbert is all about the truth.

(OK, truthiness.)

Anyway, here ‘tis:

pffsu