全部的url

  const destinationURL = 'https://example.com';
  const statusCode = 301;
  
  async function handleRequest(request) {
    return Response.redirect(destinationURL, statusCode);
  }
  
  addEventListener('fetch', async event => {
    event.respondWith(handleRequest(event.request));
  });
  

基于domain

  const base = 'https://example.com';
  const statusCode = 301;
  
  async function handleRequest(request) {
    const url = new URL(request.url);
    const {pathname, search} = url;
    const destinationURL = base + pathname + search;
    return Response.redirect(destinationURL, statusCode);
  }
  
  addEventListener('fetch', async event => {
    event.respondWith(handleRequest(event.request));
  });
  
Last modification:December 22, 2022
如果觉得我的文章对你有用,请随意赞赏