以前一直用着是CF官方的重定向列表,但是太少了,上网搜索,遂找到Workers方案:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 addEventListener ("fetch" , event => { event.respondWith (handleRequest (event.request )) }) async function handleRequest (request ) { const arr = [ "[重定向前链接] [重定向后链接]" , ] let old_url, new_url for (const u2 of arr) { [old_url, new_url] = u2.split (' ' ) if (request.url === old_url) { return Response .redirect (new_url, 301 ) } } const base = "404时跳转的 URL" const url = new URL (request.url ) const { pathname, search } = url const destinationURL = base + pathname + search return Response .redirect (destinationURL, 301 ) }
把代码粘贴进 Worker 然后绑定一个域名即可。