Remove query strings before sending request to origin
Remove certain query strings from a request before passing to the origin.
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;  },};Was this helpful?
- Resources
- API
- New to Cloudflare?
- Products
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark