Redirect root domain of custom short URLs using bit.ly pro

Update: Bitly Pro is now just Bitly

We recently used bit.ly pro to implement custom short urls for 511contracosta.org – with 511cc.org. Its currently a free service and works the same as bit.ly shortened URLs, only with a custom domain name of your choosing. Amazon just announced yesterday that they are using bit.ly pro for custom URLs using amzn.to.

Things worked great, and it was easy to set up the custom url with bit.ly pro by changing the A record for the domain name, however this meant that anyone going to 511cc.org directly with no hash on the end would be redirected to bit.ly’s main page. We needed this to redirect to a URL of our choosing, in this case 511contracosta.org. This isn’t an option in bit.ly pro, according to their FAQ its only available for bitly.Pro Enterprise users which costs $995/month. This was way beyond our price range.

Fortunately, its pretty easy to use .htaccess to carry out this.

  • First, you need to set up the short domain name to use namesevers that point to a hosting account you control. For us, this was Media Temple so we set nameservers to ns1.mediatemple.net and ns2.mediatemple.net.
  • Next, add a file called .htaccess
  • The contents of the .htaccess file should be:

    RewriteEngine on
    RewriteRule ^/?$ http://511contracosta.org [L]
    RewriteRule ^(.*)$ http://bit.ly/$1 [R=301,NC]
    view raw file1.txt This Gist is brought to you using Simple Gist Embed.

  • You should replace “http://511contracosta.org” with the domain name you’d like to redirect the root to
  • Enjoy bit.ly pro, with at least one feature of bitly.pro enterprise

19 Responses to “Redirect root domain of custom short URLs using bit.ly pro”

  1. [...] order to get a homepage that allows others to access the service, we took a lesson from the guys who created 511cc.org using [...]

  2. [...] order to get a homepage that allows others to access the service, we took a lesson from the guys who created 511cc.org using [...]

  3. Hi, does this still work since bitly requires you to set an A record that points to their IP

  4. [...] – that small feature is for only $995 / mo for Enterprise customers. Instead, I might try using .htaccess, but it feels like a hack. Bit.ly already puts 1 hop between you and your destination. Using that [...]

  5. hi, i don't get it. how do i connect to short url to my webspace on the nameserver of my provider?

  6. @dax This technique still appears to work.

  7. The web staff at 411 New York wishes to thank you for this post as it helped.
    After seeing pep.si being forwarded to pepsi.com we had to have it for http://411ny.org

  8. Glad this worked for you. We've now switched away from using bitly pro to a self-hosted implementation of YOURLS http://yourls.org/ – a php script that offers the same features as bit.ly pro but doesn't share the namespace. This means we can use anything for the trailing characters – like http://511cc.org/bike and not have to worry about conflicting with another bit.ly user. Its very easy to set up and offers statistics and other customization options.
    http://yourls.org/

  9. I came across your blog post while I was searching for bitly’s “root domain redirect” feature. Glad I found about YOURLS. I’ll give it a try too! Thank you for sharing the tips!

  10. This is awesome, I implemented it a while ago on http://cjgw.in and it works brilliantly.

    However, I really wanted to have custom short URLs and didn’t want to use YOURLs because it’s a bit of a hassle (compared to using bit.ly), and because there are so many plugins available that work directly with bit.ly which made this even easier to use (since bit.ly automatically returns your custom URL to the plugins).

    Instead, I figured out a way of creating your custom short URLs in the .htaccess file! I’ll blog a tutorial and refer to this post since it was here that I got the initial knowledge, but all you have to do is add the following line before the rest of the RewriteRules:

    RewriteRule ^CustomShortURL$ BitlyShortURL [L]

    Note that this will also work going DIRECTLY to your resultant URL, rather than via bit.ly:

    RewriteRule ^CustomShortURL$ http://end.website.com [L]

    For example, I have http://cjgw.in/quiz setup to go to http://bit.ly/nzutFQ, which I like because I get all of bitly’s reporting features. That looks like this:

    RewriteRule ^quiz$ nzutFQ [L]

    If I wanted to, I could send http://cjgw.in/quiz directly to my blog post.

    Hopefully, this will be useful to anyone who wants to use whatever short URL they want, and change at as and when they see fit :-)

    P.S. If anyone fancies taking that quiz (http://cjgw.in/quiz), I’d REALLY appreciate it because it’s part of my master’s dissertation on Digital Literacy.

  11. P.S. I’ve written a tutorial on what I said in my comment above here: http://cjgw.in/oGVEb4 in case the above is not clear!

  12. Since I’m not seeing the result expected, I jsut want to make sure I’m doing it right:

    1. I created a file in notepad name only .htaccess, that had only the above 3 code lines.

    2. I uploaded the file to my host to the following folder: /x/dta

    3. I configured in my host 1and1 the domain to the following destination: /x/dta

    Still nothing happened.

    For the record, I deleted the Bitly html file and changed the A-record IP address back to 1and1. Neither of the changes stopped my custom shorted urls from working.

    Help, anyone?

  13. Just used this code to set up http://jaqandre.ws to redirect to http://jaqandrews.com but still use bit.ly for most short URLs. Thanks! Still works!

  14. Wanted to drop by and say that this was really helpful. I just saved myself $995 / month.

  15. Brilliant, worked like a charm. Makes a lot of sense too.

  16. These instructions may not work on all hosts – make sure your host supports using .htaccess files and that you place it in the web root directory.

  17. [...] to BlinkTag for this awesome code. Bitly Pro Enterprise account offers this and many other services for $995 [...]

  18. Awesome (Y) Did what I could http://emgz.in/UNAXfL ;)

    Thank for his Wonderful code.

  19. Just an update for new readers. Bity might send you a similar email.

    —Message—
    You configured a custom short domain (411ny.org) with bitly on October 25 2011. We have detected a configuration problem in the DNS for 411ny.org. Please visit bitly for information on how to update your DNS settings.
    —Message—

Leave a Comment