Advanced Custom Bitly Domain

I recently helped a client setup a custom domain for their bitly account.  Bitly of course makes this extremely easy except for one small thing:  We wanted the root domain to redirect to their main site.

To give an example, let’s say I had a custom short domain of “amit.st” that I wanted to use for redirecting people to “amitstreet.com”.  The standard approach is to point the A-Record of that domain to Bitly’s IP address.  And for any shared link, this will redirect fine, but if someone gets curious and wants to type in just “http://amit.st” they’ll get redirected over to “http://bit.ly” which is not what I want.

So after a quick Google search, I found the answer, and I’ll share it here:

First: Point your DNS at your own server (i.e. do NOT point your A-Record at Bitly’s IP Address)

Next: use this code base in your .htaccess file:

Options +FollowSymLinks
RewriteEngine on

RewriteRule ^$ xUniVT [L]
RewriteRule ^custom$ yX3Lbm [L]

RewriteRule ^/?$ http://amit.st/ [L]
RewriteRule ^(.*)$ http://bit.ly/$1 [R=301,NC]

To use this code

1) replace “amit.st” with your own custom domain

2) In your bitly account, create a redirect to your home page

3) In Line 4 of the .htaccess code, replace the “xUniVT” with whatever bitly generates for the hompepage redirect you made in step 2

4) Line 5 is a little bonus: Instead of giving people “amit.st/4rReses” (which is bitly’s autogenerated URLification), you can make your own human-understandable shortness (i.e. amit.st/cool) and replace the “custom” with “cool” (remember, see line 5), and replace the “yX3Lbm” with whatever bitly autogenerates for you.


Posted

in

by

Tags:

Comments

2 responses to “Advanced Custom Bitly Domain”

  1. Richard Giles Avatar

    Looks good, though am I right in saying that you can’t use bit.ly’s custom domain feature as you’re not pointing the domain to them?

    It’s great to redirect the root domain, but then you can’t use their actual services.

  2. Amit Savyon Avatar
    Amit Savyon

    Well, I’m saying that their custom domain feature doesn’t (or didn’t, when I wrote this post) allow you to map just the root domain to redirect to your main site. That’s the whole issue I got around with this method described here

Leave a Reply

Your email address will not be published. Required fields are marked *

What is 14 + 11 ?
Please leave these two fields as-is:
Quantum physicists only. Solve this complex mathematical equation to proceed.