Bulk URL Redirection with Cloudflare Workers Script

Bulk URL Redirection with Cloudflare Workers Script
August 11, 2025

If you’ve ever had to fix broken links or change page URLs, you know how important URL redirection is for keeping both visitors and search engines happy. Old pages showing 404 errors can waste Google’s crawl budget and hurt rankings. The solution? Point them to the right place using SEO redirects.

For sites connected to Cloudflare, one of the best ways to handle large numbers of redirects is with a Cloudflare Workers script.

Why I Chose Cloudflare Workers for Bulk Redirects

I was managing SEO for a client with sites built on One-Page CMS platforms like WordPress and Webflow. Normally, I’d use a CMS redirect option or plugin, but none were available.

Since the sites were already integrated with Cloudflare, I tried their built-in redirect rules, but the Cloudflare free plan redirect limit is only 10 URLs. That’s nowhere near enough for large SEO projects.

That’s when I switched to Cloudflare Workers. With Workers, you can create unlimited redirects using JavaScript on Cloudflare’s edge network. This means the redirect happens instantly before the request even hits your server.

A few things to keep in mind:

  • Worker scripts have a 1 MB code size limit
  • Execution time is 10ms CPU time on the free plan (more on paid plans)

Still, for most bulk redirection needs, this is more than enough.

Benefits of Using Workers for SEO Redirects

  • No redirect limit like with Cloudflare Page Rules
  • Supports 301 permanent redirects and 302 temporary redirects
  • Runs on Cloudflare’s global network for fast response times
  • Keeps your server load low since redirects happen at the edge

How to Set Up Bulk Redirects in Cloudflare Workers

Step 1: Map Your Old and New URLs

Make a spreadsheet with every old URL and its correct new destination.

  • Don’t leave any old link unmapped
  • Save the file (CSV format) for the next steps

Step 2: Use a Base Cloudflare Worker Script

Here’s the general JavaScript redirect script you’ll start with:

const redirects = {

  “/services/trigger-point-treatment/”: “https://northstarmedicalmn.com/trigger-point-injections”,

  “/services/spinal-decompression/”: “https://northstarmedicalmn.com/spinal-decompression-therapy”

};

addEventListener(“fetch”, event => {

  event.respondWith(handleRequest(event.request));

});

function normalizePath(path) {

  return path.endsWith(“/”) ? path : path + “/”;

}

async function handleRequest(request) {

  const url = new URL(request.url);

  const path = normalizePath(url.pathname);

  if (redirects[path]) {

    return Response.redirect(redirects[path], 301);

  }

  return fetch(request);

}

Step 3: Bulk Generate Redirect Rules with Manus

  • Go to https://manus.im/
  • Start a new chat
  • Upload your CSV from Step 1
  • Paste the base script and ask Manus to replace the redirect list with your own URLs

Step 4: Deploy Your Cloudflare Worker

  1. Go to Cloudflare → Workers & Pages → Create application
  2. Choose “Hello World” to start
  3. Name your Worker (e.g., brandname-seo-redirects)
  4. Click Deploy
  5. Edit the code, replace it with your updated Worker script, then deploy again

Step 5: Link the Worker to Your Domain

  1. Remove old redirect rules
  2. Go to your domain in Cloudflare
  3. Open Workers Routes
  4. Add a route like: example.com/*
  5. Select your Worker and save

Troubleshooting Cloudflare Workers Redirects

If your bulk redirects aren’t working:

  • Check your script for typos
  • Try different route patterns:
    • www.example.com/*
    • *.example.com/*
    • *www.example.com/*
  • In DNS settings, make sure all records are proxied (orange cloud icon)

Final Thoughts – Wahaj Ansari

If you’re running into Cloudflare redirect limits and need to handle hundreds or even thousands of SEO redirects, a Cloudflare Workers script is the way to go. It’s fast, flexible, and perfect for bulk URL redirection without relying on server plugins or CMS features.

DISCLAIMER:
I write all my content based on my own experience, research, and what I’ve learned from working in Marketing and SEO. To make the English easier to understand, I use AI tools to rephrase it. The information stays the same, just written in a simpler way so everyone can understand.


Discover more from Wahaj Ansari

Subscribe to get the latest posts sent to your email.

Leave a Reply

Your email address will not be published. Required fields are marked *

Discover more from Wahaj Ansari

Subscribe now to keep reading and get access to the full archive.

Continue reading