跳转到内容
本站为社区维护的非官方中文翻译,与 Cloudflare, Inc. 无关联。本站不提供账户登录,请勿在任何非官方站点输入您的 Cloudflare 账户信息。官方文档:developers.cloudflare.com

从一个域名重定向到另一个域名

将所有请求从一个域名重定向到另一个域名。

最后更新 查看 MarkdownAgent 设置
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);
	},
};

这篇文档对您有帮助吗?