Show HN: Tiny Redirects - Git-based URL shortener using _redirects

3 days ago 1

tiny-redirects is a minimal Git-based redirect management system that lets you configure short URLs using YAML files. All redirect entries are compiled into a static _redirects file, ideal for deployment on Netlify/Cloudflare. In this case Netlify is preferred because Decap CMS integrated seemlessly with Netlify.

  • All .yaml files inside the redirects/ folder are processed.
  • The build.py script reads, validates, and converts them into a single _redirects file.
  • This _redirects file can be served directly by Netlify to handle static redirects.
  • If deployed on Netlify, urls can be added via Decap CMS

image

tiny-redirects/ ├── redirects/ # Folder for all redirect YAML files │ ├── example.yaml │ └── blog-redirects.yml ├── _redirects # Output file generated by build.py, served by Netlify ├── build.py # Script to compile YAML redirects into _redirects ├── admin/ │ └── config.yml | └── index.html # Entry point for CMS admin UI └── README.md

1. Add Redirect YAML Files

Each file should contain redirect entries like:

- short_url: "/cv" target_url: "https://rishikeshs.com/docs/cv.pdf" status_code: 301

Or, if editing via CMS:

redirects: - short_url: "/cv" target_url: "https://rishikeshs.com/docs/cv.pdf" status_code: 301

Note: build.py supports both formats.

This generates a _redirects file at the project root.

Once _redirects is present, Netlify will automatically handle the redirects during deployment. In Netlify, set build command as python3 build.py

Decap CMS Integration (admin UI)

  • admin/config.yml is preconfigured for use with Decap CMS (formerly Netlify CMS).
  • It uses GitHub as a backend, and authentication is handled by Netlify Identity.
  • Visit /admin on your deployed site to use the admin panel.

config.yml sample:

backend: name: github repo: rishikeshsreehari/tiny-redirects branch: main media_folder: "static/uploads" public_folder: "/uploads" media_library: name: uploadcare collections: - name: 'redirects' label: 'Redirect Files' folder: 'redirects' create: true extension: 'yaml' format: 'yaml' slug: '{{slug}}' summary: '{{filename}}' fields: - label: 'Redirects' name: 'redirects' widget: 'list' label_singular: 'Redirect' fields: - label: 'Short URL' name: 'short_url' widget: 'string' - label: 'Target URL' name: 'target_url' widget: 'string' - label: 'Status Code' name: 'status_code' widget: 'number' default: 301

The file blog-redirects.yml inside the redirects/ folder is auto-generated from an external repository for personal use. Reference: https://github.com/rishikeshsreehari/personal-blog/blob/main/scripts/short_url.py


Read Entire Article