In the realm of site migrations, there are times when you'll face a roadblock. Perhaps you can't access the hosting of the source site, or the CMS of the source site doesn't cater to bulk redirects, or you simple don't want to continuing paying for hosting to implement redirects and prefer to implement these redirects directly at the DNS level.
When the architecture of your site undergoes a transformation, especially when you're dealing with a vast number of pages, things can get tricky. If you've thought of using Cloudflare's built-in "bulk redirect" tool, you'll quickly find its limitations, with only 20 redirects for Free Users, 500 for Pro Users, and 10,000 for Enterprise Users. Details on their availability can be found here. But what if you have a website with more than 10,000 pages and each of them needs individual mapping? Or what if you're not quite ready to invest in an upgrade for just this feature?
Enter the Cloudflare worker, a potent tool that can handle this challenges:
Below is a simple yet effective code for the Cloudflare worker that can manage the redirects:
export default {
async fetch(request) {const redirectMap = new Map([
["/about-us", "https://destinationurl.com/about-us"],
["/about-us/team", "https://destinationurl.com/about-us/team"],
["/about-us/csr", "https://destinationurl.com/about-us/csr"],
]);
const requestURL = new URL(request.url);
const path = requestURL.pathname;
const location = redirectMap.get(path);
if (location) {
return Response.redirect(location, 301);
}
// If request not in map, return the original request
return fetch(request);
},
};
This code is a nifty tool that uses a map structure to dictate the redirects. All you need to do is list down the old and new URLs in pairs, and the worker will seamlessly guide your users to the right pages.
Site migrations are complex, and with the constant evolution of digital infrastructure, you'll need powerful tools in your toolkit. This Cloudflare worker is an example of how you can adapt and navigate efficiently through the challenges, ensuring smooth transitions for your users and maintaining the SEO value of your older URLs.
Remember, the key is in details, preparation, and the right tools. Happy migrating!
We have been informed of an ongoing scam conducted through WhatsApp and other messaging platforms, falsely promising employment or payment to individuals. Please be aware that these communications are not associated with Bravr Ltd. They will attempt to direct you to a website that has a similar domain to ours with additional characters. This is a scam website and has nothing to do with us. We urge everyone to report such activities to the police and through the messaging platforms used for contact.
Please see our Fraud Prevention page for more details
Do not make any payments or disclose personal information. Official communications from our company will always come from an email address ending in @bravr.com.
Stay vigilant and safe.
Shah - Founder of Bravr Ltd.