跳转到内容
搜索文档

在发送请求到源站前删除查询字符串

在将请求传递给源站之前,从请求中删除某些查询字符串。

最后更新 查看 MarkdownAgent 设置
export default {
	async fetch(request) {
		// Define the query strings you want to remove
		const queryStringsToRemove = ["utm_source", "utm_medium", "utm_campaign"];

		// Get the URL from the request
		const url = new URL(request.url);

		// Remove the specified query strings
		queryStringsToRemove.forEach((query) => {
			url.searchParams.delete(query);
		});

		// Create a new request with the modified URL
		const modifiedRequest = new Request(url, request);

		// Pass the modified request to the origin
		const response = await fetch(modifiedRequest);

		return response;
	},
};

这篇文档对您有帮助吗?