DEV Community

Cover image for Personal URL shortener with Netlify Redirects
Waylon Walker
Waylon Walker

Posted on • Originally published at waylonwalker.com

Personal URL shortener with Netlify Redirects

Photo by Ozark Drones on Unsplash

I love using URL shorteners to easily share links without hitting character limits, but they loose their meaning. Services like bit.ly will save my links for me so that I can find them, but I would rather them to be easy to remember. https://bit.ly/2ruLwQz does not roll of the tongue so well.

301 πŸ€Έβ€β™€οΈ

I recently discovered a really cool feature of netlify that I have always looked past, _redirects. It is so simple cool and powerful, every netlify site should do this!

But how πŸ€·β€β™€οΈ

simply add a _redirects file to the root of your your published site with the following format. The trick I found with my gatsby site was that it needed to be in my static directory /static/_redirects, not root. Next you just put space separated links on separate lines. #'s can be used for comments.

# netlify redirects
# from_url to_url

# Short-Blog

/blog/scli         /blog/simple-click/
/blog/cmdt         /blog/cmd-exe-tips/
.
.
.


# splats

/b*             /blog/:splat
/n*             /notes/:splat


# External

/twitter        https://twitter.com/_WaylonWalker
/github         https://github.com/WaylonWalker
/devto          https://dev.to/waylonwalker/

Enter fullscreen mode Exit fullscreen mode

πŸ™Œ Share those short links

Now with shorter links we have more space for our content without needing to use a service like bit.ly that makes our links unreadable.

This page was originally posted on my personal blog https://waylonwalker.com/b/purl/

Top comments (1)

Collapse
 
irreverentmike profile image
Mike Bifulco

Hey Waylon - thanks for the helpful post! I'm going to set up something similar for myself. I'm curious - what's a splat?

Annnnnd PS - I've also got a background in Mechanical Engineering! ✊