Same origin for www websites - 404 error

Hi, I set up a worker on CloudFlare following your guide, but I get 404 error when checking the /healthy/ link.

I’m assuming it’s because all traffic is redirected from busines-unicorn.com to www-business-unicorn.com.

Are there any changes I need to do in the worker in order for that to work?

worker:

export default {
  async fetch(request, env, ctx) {
    let { pathname, search, host } = new URL(request.url);
    
    pathname = pathname.replace('/myw/', '/');
    const domain = 'myw.business-unicorn.com';

    let newRequest = new Request((`https://` + domain + pathname + search), request);
    newRequest.headers.set('Host', domain);
    
    return fetch(newRequest); }, };

I tried to set route both to www.business-unicorn.com/myw* and also business-unicorn.com/myw*, but it still didn’t work.

The website is built on webflow using custom domain. I already configured same origin for another client using webflow, so that shouldn’t be a problem like on Shopify pages?

Some screenshots:


Hello!

First of all, please check that your site’s traffic is also proxied through Cloudflare, otherwise, the Same origin won’t work.

As for the setup you’ve shared, I have a couple of comments regarding that.

There’s no need to include “www.” anywhere in your worker/route/rules.

The code for the worker looks correct to me.

But the route should be “business-unicorn.com/myw*”, without “www.”.

Also, the custom filter expression for the rules you’ve created should be “URI path equals myw”, not “contains”.

Please check the guide here to make sure that you’ve set up everything correctly:

@Nick_Foggy is completely right in the first sentence, the problem is that your site traffic is not proxied through Cloudflare, so what you do on the CF side doesn’t work. The request just doesn’t get there, it is processed by your server and returns a 404 because the page doesn’t exist.
For this to work you need to proxy all your domain traffic through CF as well.

Hey, guys,

thanks for replying. I totally forgot about this thread. It turns out one of the developers disabled proxy and It never occured to me, that one would do that.

Thanks again!
Gašper