Bulk redirect based on a map object · Cloudflare Rules docs | Latest TMZ Celebrity News & Gossip | Watch TMZ Live Skip to content
Cloudflare Docs

Bulk redirect based on a map object

Redirect requests to certain URLs based on a mapped object to the request's URL.

export default {
async fetch(request) {
// Define a variable with the hostname that needs to be redirected.
const externalHostname = "example.com";
// Define the map object. Replace the sources (/pathX) and targets (/redirectX) with ones that apply to your case.
const redirectMap = new Map([
["/path1", "https://" + externalHostname + "/redirect1"],
["/path2", "https://" + externalHostname + "/redirect2"],
["/path3", "https://" + externalHostname + "/redirect3"],
["/path4", "https://cloudflare.com"],
]);
// Clone the original URL.
const requestURL = new URL(request.url);
// Check the request path against the map and redirect accordingly.
const path = requestURL.pathname;
const location = redirectMap.get(path);
if (location) {
return Response.redirect(location, 301);
}
// If request path not in map, return the original request.
return fetch(request);
},
};

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.