A lightweight URL redirector service built on Cloudflare Pages. It performs 301 permanent redirects based on per-domain environment variable rules, with an optional default fallback.
All incoming requests are handled by a single Pages Function (functions/[[path]].ts). The function:
- Reads the source hostname from the request.
- Looks up a matching environment variable (
FROM_<domain>). - Falls back to
DEFAULT_TARGETif no specific rule matches. - Returns a 301 redirect to
https://<target><path><query>.
If neither a specific rule nor DEFAULT_TARGET is set, a 500 error is returned.
Forwarding rules are defined as environment variables. Domain names are converted to variable keys by replacing . and - with _, then prefixed with FROM_.
| Environment Variable | Effect |
|---|---|
FROM_example_com = "target.com" |
example.com/* → target.com/* |
FROM_www_example_com = "example.com" |
www.example.com/* → example.com/* |
FROM_my_site_org = "newsite.com" |
my-site.org/* → newsite.com/* |
DEFAULT_TARGET = "tiy.ai" |
Fallback for any unmatched domain |
Local development: set variables in wrangler.toml under [vars].
Production: configure via Cloudflare Dashboard → Pages → Project Settings → Environment Variables.
npm install # Install dependencies
npm run dev # Start local dev server (Wrangler Pages)
npm run build # Build with Vite
npm run deploy # Build + deploy to Cloudflare PagesMIT