Using _redirects as a manual URL shortener?

Hi folks – I currently have my main site - polaine.com - built in Hugo deployed on Netlify. Continuing my migration from Dreamhost, I have one small site that uses Yourls as a personal URL shortener, which is PHP-based and uses the domain pln.me.

I only really use it for conference presentations or personal URLs. For example https://pln.me/blurb redirects to my About page on Polaine.com or pln.me/uxaus21 would be a URL for the slides from for a UX Australia 2021 presentation, for example (that one isn’t real). You get the idea.

Since I don’t use it often and since there are only about 1,000 entries that I could easily export, I was wondering if it would be possible to make a static site deployed on Netlify that only has a _redirects file with those entries and that’s it. Anytime I needed a new one, I’d just add the entry to that file.

Is that possible? Does it break any Netlify policies? SEO isn’t an issue for me here.

Hi @apolaine. Great question. It’s absolutely doable, in a lot of different ways, actually. Here’s a great article by Netlify’s team on creating a dynamic URL shortener using redirects:

You don’t need to use forms and functions though. If you like your shortener to be behind a login, you can simply use Netlify CMS to input the urls. With the data the CMS outputs, you can then generate the redirects file (or netlify.toml) with your SSG, or even with a simple build script. There’s a ton of options depending on your weapon of choice. It does not break any Netlify policies whatsoever.

1 Like

Thanks Tom. I did read that article and wondered if it might be overkill for my needs and beyond my coding skills to put together.

Presumably Netlify needs something to build, though. What happens if all I have is a _redirects file and nothing else?

1 Like

Netlify doesn’t actually need to build anything. you can deploy static HTML from a Github repo, leaving the build command blank. I think the same goes for a redirects file, you’ll just have to manually edit it through git. I’ve never tried, but I think it should work!

Thanks. I’ll give it a go.

1 Like

Great! Let me know how it goes