Tag Archives: redirects

Ajax apache bit.ly firefox firefox add-on Google Plus Greasemonkey iframe Javascript kludge social networking tinyurl Twitter url shorteners vanity url xmlhttprequest

How to get a nice, short Google Plus profile link

One thing Twitter and a lot of other social sites have that Google+ lacks is a nice, short url to give to people. I can say:

“Nice to meet you, I’m at twitter.com/iamjason.”

And there I am. That’s a lot easier than saying:

“Why hello there, would you like to follow me at https://plus.google.com/u/0/101453275162405736930/posts?”

After the 6th digit or so people wander off. Just imagine trying to spell it out during a candlelit dinner on your first date with someone. Ruins the mood.

I could use a redirect service, like gplus.to, for a vanity url, but then they get to see who’s going to my profile and it’s sort of up to them if it keeps working.

So now I just tell everyone to go to jasonmorrison.net/+. It’s easy to set up, if you have your own domain. Here’s how to do it if your web server is running Apache, which is pretty common:

Step 1: FTP to your server, go to the root directory for your site, and open or create an .htaccess file.

Step 2: Put this in your .htaccess file:

Redirect permanent /+ https://plus.google.com/u/0/(your profile id)/posts

This will create a 301 (permanent) redirect to your profile, which also tells search engines that you mean business.

Step 3: Order a new box of business cards, with your spiffy new Google+ profile link.

Hope this helps!

TinyUrl Trouble: Greasemonkey drops the location header in GM_xmlhttpRequest

I get a lot of ideas. Most of them wander aimlessly in my head until they become obsolete, but once in a while I’ll get an idea that seems useful and simple enough to do in my free time.

If you’ve used Twitter, you’ve seen the myriad of url shortening services like TinyUrl and Bit.ly. Url shortening services are a kludge and they break one useful, built-in feature of the web, which is the ability to know where you’re going when you click a link.

So I thought, this is something that I could fix in an hour or so with a Greasemonkey script. If you have no idea what I’m talking about, Greasemonkey is a Firefox Plugin that runs in your browser and lets you run your own Javascript on pages you load. Greasemonkey comes with a handy-dandy AJAX function called GM_xmlhttpRequest.

I figured all I have to do is grab all the anchors on the page, see if they match a list of shortener urls, do an xmlhttpRequest for each one and grab the final location (after the service finishes with it’s redirecting) from the headers.

Something along these lines:

function getTargetUrl(short_url) {

  GM_log('Getting '+short_url);

      method: 'GET',
      url: short_url,
      headers: {
          'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
          'Accept': 'text/html'
      onload: function(responseDetails) {
          GM_log('Done.  Status ' + responseDetails.status +
                ' Text ' + responseDetails.statusText + '\n\n' +
                ' Headers:\n' + responseDetails.responseHeaders);

Continue reading