Results tagged “short URLs”

short-url.png


I hate depending on third-party web services that could go dark at any minute. I've used great services like TinyURL, bit.ly and is.gd to post links to Twitter and other social media sites, but wanted to roll my own tiny URL generator so I could "own" these in-bound links.

My Movable Type-powered blog links are like so: http://apb.me/YYYY/MM/title-of-post/. Depending on the length of the entry title, these URLs can get quite long, so I've turned them into http://apb.me/###.

Here's how:

1. Find your .htaccess file via FTP. Likely, Movable Type has generated this file for you and it contains important code, so make a copy of it in a safe place.

You'll probably see code that starts with

## %%%%%%% Movable Type generated this part; don't remove this line! %%%%%%%

2. Copy the entire file and make a Movable Type index template, outputting to .htaccess.

3. Above MT's own code, add the following:

<mt:Entries lastn="99999">
Redirect 301 /<mt:EntryID> <$mt:EntryLink$>
</mt:Entries>

4. Save and republish the index template.

That's all that you need to do! Now, you have a shortened URL that takes the MT entry ID and redirects to the full post.

To find MT's entry ID for a post, go to the "Manage" - "Entries" screen and scroll over an entry. MT's link will be something like http://domain.com/cgi-bin/mt.cgi?__mode=view&_type=entry&id=19&blog_id=6. In this case, the entry ID is 19, so http://domain.com/19 should redirect to the full post.

For example, this entry is at http://mt.apb.me/mt.cgi?__mode=view&_type=entry&id=19&blog_id=6, so http://apb.me/19 will redirect to http://apb.me/2009/06/short-urls-with-movable-type/.

I still keep my permalinks at the full long URL for SEO purposes, but having a short URL that I can pass around can be very helpful. You could also add this URL to your permalink pages so others can benefit from the short link.

Bonus Points: If your domain is long to begin with (my old was http://www.aaronbailey.com), buy a short domain (check .me, .ly, .at, .in registrars) and point it at another directory on your webhost. Then have MT output another htaccess file to that location.

In a follow up post, I'll explain other methods for doing this same thing and how use your short domain to post links that aren't yours.

1
Close