URL Encoding and Hashbang Hell
04 Mar 2012Thanks to reader Steve Gricci, I have learned that BackTweets no longer exists, presumably because BackType was acquired by Twitter. (Regardless, why let the domain expire?) Until today, I have been using BackTweets for the "tweets" link at the top of each post, so anyone who clicked it recently was greeted by a parked Go Daddy page instead of seeing all tweets related to a particular post. Yikes!
My quick fix is to use Twitter instead, but their hashbang URLs make it difficult to link directly to anything. Thankfully, if you want to search for tweets that mention something simple like brooklynbeta
, you can use an ordinary URL like this:
http://twitter.com/search/brooklynbeta
No hashbang. It just works. Nice! Maybe this will be easy after all. Let's try a search for a URL:
http://twitter.com/search/http://twitter.com/
Account suspended? That's weird. While this error message isn't very helpful (maybe @search is the account that was suspended), the fault in this case is ours. We're using a query that has special characters, but we didn't bother to URL encode it. Our bad. Let's try that again:
http://twitter.com/search/http%3A%2F%2Ftwitter.com%2F
The page doesn't exist? But, we're doing the right thing now! Okay, fine, maybe we have to use the hashbang URL after all:
http://twitter.com/#!/search/http%3A%2F%2Ftwitter.com%2F
Hooray! Well, almost. If this works for you, I recommend going to your Twitter settings and checking the box to always use HTTPS. Once you've done this, you'll be told the page doesn't exist. It seems that Twitter is decoding the query when it redirects. Maybe we can just URL encode it twice to compensate for Twitter's decoding?
http://twitter.com/#!/search/http%253A%252F%252Ftwitter.com%252F
Hooray! But wait, what if we don't check the box to always use HTTPS? We won't get redirected, so Twitter won't decode our query. We'll actually be searching for http%3A%2F%2Ftwitter.com%2F
instead of http://twitter.com/
. What can we do? We can do this:
https://twitter.com/#!/search/http%3A%2F%2Ftwitter.com%2F
Because Twitter doesn't redirect HTTPS to HTTP, this avoids the redirect, regardless of the user's settings. Hooray?
There is a lesson here. URLs are underrated. Making it extremely easy and obvious for users to link to your content should be a priority. Let's try our best to remember this, even when it seems difficult to push the Web forward without abandoning its past.
Luckily, it sounds like Twitter hashbang URLs will soon be a thing of the past. That's very good news.