Technical SEO · FREE SEO UTILITY

Cloudflare Workers Edge SEO 301 Redirect & Header Generator.

Generate a zero-latency ES Module Cloudflare Worker with O(1) Map-based 301 redirects and automatic staging X-Robots-Tag protection.

Edge redirect rules3
const REDIRECT_MAP = new Map([
  ["/old-services/seo", "/services/seo-agency"],
  ["/blog/2022-guide", "/guides/seo-playbook"],
  ["/contact-old", "/contact"]
]);

export default {
  async fetch(request) {
    const url = new URL(request.url);
    const target = REDIRECT_MAP.get(url.pathname);
    if (target) {
      const destination = target.startsWith("http") ? target : new URL(target, url.origin).toString();
      return Response.redirect(destination, 301);
    }
    const response = await fetch(request);
    if (url.hostname.toLowerCase() === "staging.yourwebsite.co.il") {
      const headers = new Headers(response.headers);
      headers.set("X-Robots-Tag", "noindex, nofollow");
      return new Response(response.body, { status: response.status, statusText: response.statusText, headers });
    }
    return response;
  }
};

How to use this in your SEO workflow

  • Executing 301 redirects at the CDN edge eliminates origin round-trips and keeps Googlebot TTFB ultra-low.
  • Using a JavaScript Map avoids expensive sequential regex evaluation across hundreds of legacy URLs.
  • Automatically attach X-Robots-Tag: noindex on staging hostnames so preview deployments never leak into Google.
Map full URL migrations in Site Migration
More utilities in this category:

Related in-depth SEO guides

SEO Academy