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_date
are accurate. -
Set up Workers KV namespace:
Create a KV namespace named
RULES
from the Cloudflare dashboard, replace theid
field inwrangler.toml
with the actual ID from Cloudflare dashboard.
- Go to the Cloudflare dashboard.
- Navigate to Workers KV and find your
RULES
namespace. - 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 deploy
OR
wrangler deploy
src/index.ts
: Main worker code. It fetches the rules from KV and performs redirects.- Configuration files:
.editorconfig
,.prettierrc
for coding standards;tsconfig.json
for TypeScript settings. - Deployment files:
wrangler.toml
,package.json
for 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.