Skip to content

非公式 / UnofficialCloudflare, Inc. 非提携。アカウント情報は入力しないでください。Not affiliated with Cloudflare, Inc. Do not enter Cloudflare credentials here.Official docsこのサイトについてプライバシー

あるドメインから別のドメインへリダイレクトする

あるドメインへのリクエストをすべて、別のドメインへリダイレクトします。

最終更新 Markdown で表示Agent セットアップ
export default {
	async fetch(request) {
		// Define variables to use in the response redirect.
		const base = "https://example.com";
		const statusCode = 301;

		// Clone the original URL.
		const url = new URL(request.url);

		// Define a "pathname" and "search" variables, extracting their values from the cloned URL.
		const { pathname, search } = url;

		// Define the destination URL using the variables you declared previously.
		const destinationURL = `${base}${pathname}${search}`;
		console.log(destinationURL);

		// Respond with the redirect.
		return Response.redirect(destinationURL, statusCode);
	},
};

役に立ちましたか?