Redirect root domain of custom short URLs using bit.ly pro
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 onRewriteRule ^/?$ http://511contracosta.org [L]RewriteRule ^(.*)$ http://bit.ly/$1 [R=301,NC]
- 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

RSS
[...] order to get a homepage that allows others to access the service, we took a lesson from the guys who created 511cc.org using [...]
[...] order to get a homepage that allows others to access the service, we took a lesson from the guys who created 511cc.org using [...]
Hi, does this still work since bitly requires you to set an A record that points to their IP
[...] – 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 [...]
hi, i don't get it. how do i connect to short url to my webspace on the nameserver of my provider?
@dax This technique still appears to work.
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
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/
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!
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.
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!