跳转到内容
搜索文档

将 403 Forbidden 重定向到其他页面

如果源站返回 403 Forbidden 错误代码,重定向到其他页面。

最后更新 查看 MarkdownAgent 设置
export default {
	async fetch(request) {
		// Send original request to the origin
		const response = await fetch(request);
		// Check if origin responded with 403 status code
		if (response.status == 403) {
			// If so, redirect to this URL
			const destinationURL = "https://example.com";
			// With this status code
			const statusCode = 301;
			// Serve redirect
			return Response.redirect(destinationURL, statusCode);
		}
		// Otherwise, serve origin's response
		else {
			return response;
		}
	},
};

这篇文档对您有帮助吗?