How to Use Drupal to Create Your Own URL Shortener

URL shortener Using Drupal image

Problem: You’re over at tinyurl.com (or any of the other URL shortening services) and the shortcut you want to use isn’t available.

Solution: Use Drupal!

You might be thinking “Why would I use Drupal for such a simple service? That’s a lot to maintain for something so ‘trivial’.” Let’s think about two reasons:

  1. This will be your service. You can create an unlimited number of shortcuts without ever competing with anyone else. Have you ever shared a google doc? Here’s what the link looks like – https://docs.google.com/document/d/1UzmMA7VEsQplWnaYNIlHPvijsYYsU5a3wktoFt4_w3o/edit?usp=sharing. That’s very memorable. Now try: https://rodsurl.com/fake-doc. See the point?
  2. Drupal 10 will eventually have automatic updates. Since this site is a stand-alone “service”, enabling this feature will basically let the site take care of itself. In the meantime, a simple composer command once in a while will take care of it! (https://www.drupal.org/docs/updating-drupal/updating-drupal-core-via-composer).

Using Drupal to Create Your Own URL Shortening Service

I set this exercise up at https://rodsurl.com and its something I actually use a lot!

Here’s the frontpage for a site visitor.

When I’m logged in the front page is the Redirect module. This makes accessing this section incredibly easy.

Here are the steps you’ll take:

  1. Secure the shortest domain you can find. Of course it doesn’t need to have “url” in the name, just anything you like as long as it’s the fewest number of letters possible.
  2. Create a Drupal site at the domain.
  3. Add the Redirect module (https://drupal.org/project/redirect).
  4. Create a page for people who “stumble” onto the site.
  5. Make the Redirect module your frontpage.

Steps 1 through 3 are straightforward and covered in many other tutorials on this site (https://ostraining.setupwp.io/lessons/modules-explained/).

Step 4: Create a page for people who “stumble” onto the site.

  1. Head over to Content -> Add Content -> Basic Page.
  2. Create the content of the page to suit your liking (see the above image for mine or visit https://rodsurl.com).
  3. Head over to Configuration -> System -> Basic Site Settings and enter /node/1 in the Default 403 (access denied) page field.
  4. Click Save.

Step 5: Make the Redirect module your front page.

This is even more simple.

  1. Head over to Configuration -> System -> Basic Site Settings and enter /admin/config/search/redirect into the Default front page field.
  2. Click Save.

Now, when you’re logged in, the Redirect module is your front page!

Summary

The only thing missing from our URL Shortener service is statistics. There is a module for that, however it’s not ready for Drupal 10 at the time of this writing. There IS a patch if you’re feeling daring! (https://www.drupal.org/project/redirect_metrics).

The hardest part of this entire exercise is finding a short domain! If you use any kind of URL shortening service, having your own that’s easy to use and maintain is a really a great way to provide that service for yourself.

For a more detailed look at creating this service for yourself, we have a mini-course ready to go: https://ostraining.setupwp.io/courses/how-to-use-drupal-as-your-own-url-shortener-service/.

Author

  • Rod Martin

    Rod holds two masters degrees and has been training people how to do "things" for over 25 years. Originally from Australia, he grew up in Canada and now resides just outside Cincinnati, Ohio. He has worked in both the non-profit and for-profit worlds, in small companies and large corporations. His extensive open source experience includes WordPress, Joomla and Drupal and he really knows how to help you get the most out of the system you chose. Rod plays ice hockey a couple of times a week and rides his Goldwing motorcycle pretty much everywhere he can.

    View all posts
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x