I'm creating a WordPress site for a client and he mentioned that he would like his own custom URL shortening when sharing to Twitter.

How do I go about setting up one of these? If I had to guess, I would guess that it's a separate domain that redirects to the actual site. If that's the case, then how do I get the URL to redirect to the specific post and not just to the homepage of the site?


You could try this recipe taken from the chapter on cloning TinuURL in the book Cloning Internet Applications with Ruby -

  • Make a hash of the long url(In this case, if it will be used to redirect to one domain, you could just make a hash of the relative url)
  • Convert it to base 36 - 26 alphabets and 10 digits.
  • Set up a 301 from short/base36(hash) to long domain.

And on the long domain, you can code a controller that sends a request to the short domain to create a short url every time a new page is created.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.