Page Rule Alternatives?


#1

My website is built on an e-commerce platform. In order to use my custom domain name and drop the naming convention of the e-commerce provider, it was recommended that I use Cloudflare DNS services. Previously I just dealt with the strange website address, but I wanted 1) a more professional look and 2) SSL security in place.

My domain is through Bluehost, and I previously had around 95 redirects in place just to make simple, easy to remember links for my users. Through Bluehost, these redirects were free and unlimited, which is not the case with Cloudflare. I did not realize this until after switching over my DNS records and changing nameservers.

Needless to say, this is costly! Almost $100/month for redirects. I attempted to abandon these, but had many folks reaching out about broken links that I have previously advertised. For example, a link pointing to mydomain.ecommerceproviderdomain.com/p/coupon is redirected to mydomain.com/coupon. I have no control over this from the e-commerce side of things.

Without full RegEx support, I’m not sure what else to do. I don’t even have the option to buy any additional page rules at this point, as it seems I am maxed out. Even if I did, its way too costly to continue. Thanks for any help or suggestions,


#2

I’m moving this topic to Workers, as I’ve been wondering if there’s a Workers script that can process a list of redirects.


#3

This works:

addEventListener('fetch', event => {

  let url = new URL(event.request.url);

  if (url.pathname.startsWith("/google")) {

    event.respondWith(redirectTo(event.request));

  } else {

    return new Response("Something didn’t quite work");

  }

});

async function redirectTo(request) {

  return Response.redirect('https://www.yahoo.com');

}

You’d have to setup the routes via the API or Admin first though, but if you use a wildcard like mysite.com/* then you can make infinite redirects directly from the script, making this “free” compared to pagerules (That are also capped at 95).


#5

I was able to get this into the Workers dashboard, and it does indeed work. Is there a way to add more than one redirect in this manner? I apologize, I’m not a coder at all. If I add multiple instances of this script, it only recognizes whatever is at the bottom. It doesn’t appear to recognize wildcard entries.