Redirect to another domain

To redirect requests to a different domain, you can use the Response.redirect method. This example demonstrates how to permanently redirect (HTTP status code 301) all incoming requests to a specific URL. See example below:

import * as BunnySDK from "https://esm.sh/@bunny.net/edgescript-sdk@0.10.0"; BunnySDK.net.http.serve(async (request: Request): Response | Promise<Response> => { const destinationURL = "https://example.com"; const statusCode = 301; return Response.redirect(destinationURL, statusCode); });

Did this page help you?