すべてのプロダクト
Search
ドキュメントセンター

Edge Security Acceleration:指定したURLにリダイレクトする

最終更新日:Aug 09, 2024

このトピックでは、指定したURLにリダイレクトする方法を示すサンプルコードを提供します。

サンプルコード

const destinationURL = "https://www.example.com/"
const statusCode = 301

async function handleRequest(request) {
  return Response.redirect(destinationURL, statusCode)
}

addEventListener("fetch", async event => {
  event.respondWith(handleRequest(event.request))
})

結果

すべてのリクエストは、301 HTTPステータスコードに基づいてhttps://www.example.com/ にリダイレクトされます。