Redirector is a Cloudflare Workers script that uses Workers KV to manage and perform domain redirections.
- Redirect any domain pointed to the worker to a desired target URL.
- One place (Workers KV) to manage all your redirect rules.
- Easy to deploy and manage using Cloudflare's Wrangler.
-
Clone this repository:
git clone https://github.com/CasualCodersProjects/redirector.git cd redirector -
Install the dependencies:
npm install
-
Update
wrangler.toml:Ensure the details like
name,kv_namespaces, andcompatibility_dateare accurate. -
Set up Workers KV namespace:
Create a KV namespace named
RULESfrom the Cloudflare dashboard, replace theidfield inwrangler.tomlwith the actual ID from Cloudflare dashboard.
- Go to the Cloudflare dashboard.
- Navigate to Workers KV and find your
RULESnamespace. - Add Key-Value Pairs where keys are the domains you want to redirect and values are the target URLs.
Deploy the worker to Cloudflare:
npm run deployOR
wrangler deploysrc/index.ts: Main worker code. It fetches the rules from KV and performs redirects.- Configuration files:
.editorconfig,.prettierrcfor coding standards;tsconfig.jsonfor TypeScript settings. - Deployment files:
wrangler.toml,package.jsonfor project dependencies and scripts.
Feel free to fork this repository, make changes, and open a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
Happy Redirecting!
For more details on Cloudflare Workers and Workers KV, refer to the Cloudflare Documentation.