04
2025
06
18:36:32

Notion如何利用CF重定向到xxx.com

Notion是怎么利用Cloudflare重定向到 tutulifestyle.com 这个域名的,网上很多教程,生成Cloudflare里works的代码网站很多都失效了,


1.使用super(https://super.so)的SaaS。简单说,它可以把Notion页面变成一个访问速度比Notion页面更正常的网页,也可以按需加Footer那些稍微定制化,内容是自动同步Notion页面,这样就可以把Notion url变成 XXXXX.super.site,国内网络访问也正常。

2.创建一个Cloudfare Worker将传入的HTTP请求代理到指定的目标URL,我使用的Cloudfare worker代码附在这里,这段代码经过几次修改,大概完成的事情就是访客访问的时候让地址栏保持不变、解决重复重定向的错误、4个小时的缓存等,你可以问ChatGPT这段代码具体作用,如果需要也可以让GPT帮你修改成适用于你的代码。

小缺点:只有一个,网页左下角会显示“Made with super”,毕竟免费我可以接受。

TuTu版代码如下:

addEventListener('fetch', event =\> {  
    event.respondWith(handleRequest(event.request));  });  
  async function handleRequest(request) {  
    const targetURL = '[https://xxx.super.site](https://xxx.super.site/)';  
    const url = new URL(request.url);  
    const newURL = targetURL + url.pathname + url.search;  
  
    const newRequest = new Request(newURL, {          method: request.method,  
        headers: request.headers,  
        body: request.method !== 'GET' && request.method !== 'HEAD' ? request.body : null,  
        redirect: 'follow'  
    });  
  
    let response;  
    try {  
        response = await fetch(newRequest);  
    } catch (error) {  
        return new Response('Error fetching the target URL: ' + error.message, { status: 500 });  
    }  
  
    response = new Response(response.body, response);  
    response.headers.set('Access-Control-Allow-Origin', '\*');  
  
    if (response.status === 200 && request.method === 'GET') {  
        response.headers.set('Cache-Control', 'public, max-age=14400');  
    } else {  
        response.headers.set('Cache-Control', 'no-store');  
    }  
  
    if (request.headers.has('range')) {  
        response.headers.set('Accept-Ranges', 'bytes');  
    }  
  
    return response;  }




推荐本站淘宝优惠价购买喜欢的宝贝:

image.png

本文链接:https://hqyman.cn/post/11455.html 非本站原创文章欢迎转载,原创文章需保留本站地址!

分享到:
打赏





休息一下~~


« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

请先 登录 再评论,若不是会员请先 注册

您的IP地址是: