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
.yamlfiles inside theredirects/folder are processed. - The
build.pyscript reads, validates, and converts them into a single_redirectsfile. - This
_redirectsfile can be served directly by Netlify to handle static redirects. - If deployed on Netlify, urls can be added via Decap CMS
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
Each file should contain redirect entries like:
- short_url: "/cv"
target_url: "https://rishikeshs.com/docs/cv.pdf"
status_code: 301Or, if editing via CMS:
redirects:
- short_url: "/cv"
target_url: "https://rishikeshs.com/docs/cv.pdf"
status_code: 301Note:
build.pysupports both formats.
python build.pyThis 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
admin/config.ymlis preconfigured for use with Decap CMS (formerly Netlify CMS).- It uses GitHub as a backend, and authentication is handled by Netlify Identity.
- Visit
/adminon 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: 301The 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
