DEV Community

loading...
Cover image for Let's deploy the simplest URL redirection service to Netlify!

Let's deploy the simplest URL redirection service to Netlify!

dtinth profile image Thai Pangsakulyanont Originally published at notes.dt.in.th ・2 min read

Sometimes it's a good idea to post links under your own domain, so that you can change the link's target when needed1.

For example, I have a Ko-Fi page at https://ko-fi.com/dtinth but I never link to that URL directly; I use http://link.dt.in.th/coffee instead. Should I ever decide to use something else2, I only need to change the link destination.

One simple, low-code way to accomplish this is use Netlify's redirect feature.

  1. Create a GitHub repo and create a file public/_redirects:

     /youtube   https://www.youtube.com/channel/UClKPjyxFSkk_dPg6YzN0Miw/   302
     /coffee    https://ko-fi.com/dtinth                                    302
    
  2. Create a Netlify site linking to the GitHub repo and set up your domain.

  3. There is no step 3.

The _redirects file has a simple, machine-and-human-readable, plain-text format. To add or change links, just update the file on GitHub. I find this approach powerful because I can also update this file programmatically using GitHub's API, and teams can collaborate on this file like how they collaborate on code. One downside is that this approach doesn't track how many people used the link, we you'd have to track from the destination instead.


  1. Some URL shortener services doesn't allow you to change the link's destination unless you pay them money 

  2. like Patreon or GitHub Sponsors (the latter of which is not available in my country yet) 

Discussion (0)

pic
Editor guide