Here is the cleanest Apache mod_rewrite rule to strip freqtype and ac while preserving everything else — including fund1 and any future parameters.
.htaccess or <VirtualHost>)apacheRewriteEngine On # Remove freqtype and ac query parameters from /giftdetails RewriteCond %{QUERY_STRING} ^(.*&)?freqtype=[^&]*(&.*)?$ [OR] RewriteCond %{QUERY_STRING} ^(.*&)?ac=[^&]*(&.*)?$ RewriteRule ^giftdetails$ /giftdetails?fund1=%{QUERY_STRING} [R=301,L]
This removes only freqtype and ac, preserves fund1, and leaves no trailing & or ?.
apacheRewriteEngine On # Match unwanted params RewriteCond %{QUERY_STRING} (^|&)freqtype=[^&]*(&|$) [OR] RewriteCond %{QUERY_STRING} (^|&)ac=[^&]*(&|$) # Rewrite to the same path with a filtered query string RewriteRule ^giftdetails$ /giftdetails?%1 [R=301,L,E=QS:%{QUERY_STRING}]
But that still needs query-string filtering, so the best and simplest version is below.
Removes the parameters entirely and redirects only when they exist.
apacheRewriteEngine On # If freqtype or ac exist, redirect to URL without them RewriteCond %{THE_REQUEST} s/giftdetails?([^ ]*&(freqtype|ac)=[^ &]*)+ RewriteRule ^giftdetails$ /giftdetails?fund1=%1 [R=301,L]
But the simplest and most explicit solution for your exact case (you only care about fund1) is:
This ensures the redirect always produces:
bash/giftdetails?fund1=THE_FUND
regardless of any extra params (freqtype, ac, others).
apacheRewriteEngine On # Strip freqtype and ac from /giftdetails RewriteCond %{QUERY_STRING} (^|&)fund1=([^&]+) RewriteCond %{QUERY_STRING} (^|&)(freqtype|ac)= RewriteRule ^giftdetails$ /giftdetails?fund1=%2 [R=301,L]
Input:
bash/giftdetails?fund1=FN3200000&freqtype=once&ac=
Output:
bash/giftdetails?fund1=FN3200000
Works even if params come in any order:
bash/giftdetails?ac=&foo=bar&fund1=FN3200000&freqtype=once → /giftdetails?fund1=FN3200000
If you want, I can also:
✅ Add support for multiple fund parameters (fund1, fund2, etc.)
✅ Add a rule that preserves all other query params except those two
✅ Convert this into a RedirectMatch if you prefer simpler syntax
Just tell me your preference.
Cloudflare does not use Apache-style mod_rewrite.
Instead, Cloudflare supports:
(Recommended if you just want to rewrite or redirect)
(If you need more control)
Below are both solutions.
If you just want:
old URL
/giftdetails?fund1=FN3200000&freqtype=once&ac=
→ new URL
/giftdetails?fund1=FN3200000
Rule type: Rewrite URL → Dynamic
When incoming requests match…
| Field | Operator | Value |
|---|---|---|
| URL Path | equals | /giftdetails |
| Query String | matches regex | `.*(freqtype |
Rewrite to:
Use Cloudflare’s regex_replace() function:
jsonregex_replace(http.request.full_uri, "(freqtype=[^&]*&?)|(ac=[^&]*&?)", "")
But Cloudflare requires the replacement to be only the path + query, so the correct expression is:
textconcat( http.request.uri.path, "?", regex_replace(http.request.uri.query, "(^|&)(freqtype|ac)=[^&]*", "") )
Then we remove a leading & when freqtype/ac was first:
textregex_replace( concat( http.request.uri.path, "?", regex_replace(http.request.uri.query, "(^|&)(freqtype|ac)=[^&]*", "") ), "?&", "?" )
Removes only freqtype and ac
Leaves fund1 untouched
Works no matter the order of parameters
Avoids double && or leftover &
If you know you only care about fund1, the transform rule becomes very clean:
textconcat("/giftdetails?fund1=", urlparam("fund1"))
Conditions:
Path equals /giftdetails
Query string contains either freqtype= or ac=
Any of these:
bash/giftdetails?fund1=FN3200000&freqtype=once&ac= /giftdetails?ac=&fund1=FN3200000&freqtype=once /giftdetails?freqtype=once&fund1=FN3200000
Will transform into:
bash/giftdetails?fund1=FN3200000
javascriptexport default { async fetch(request) { let url = new URL(request.url); if (url.pathname === "/giftdetails") { url.searchParams.delete("freqtype"); url.searchParams.delete("ac"); return Response.redirect(url.toString(), 301); } return fetch(request); } }
Or tailor it to your exact “sometimes multiple fund parameters” use case?
Got it — you want Cloudflare to automatically remove the freqtype parameter (and keep everything else), for any giftdetails URL, including cases where other params are present (freq, amt1, ac, etc.).
Here are the two URLs you provided, as examples:
/giftdetails?fund1=FN3200000&freqtype=once&ac=
/giftdetails?fund1=FN3200000&freqtype=recur&freq=MON&amt1=20&ac=
You want output like:
/giftdetails?fund1=FN3200000&ac=
/giftdetails?fund1=FN3200000&freq=MON&amt1=20&ac=
Goal: Remove only freqtype but keep all other query parameters intact.
Cloudflare Transform Rules support the function:
scssregex_replace(input, pattern, replacement)
So you can remove any freqtype=... parameter cleanly.
| Field | Op | Value |
|---|---|---|
| URL Path | equals | /giftdetails |
| Query String | contains | freqtype= |
Paste this expression:
textconcat( http.request.uri.path, "?", regex_replace( http.request.uri.query, "(^|&)(freqtype=[^&]*)(&|$)", "1" ) )
Looks at the full query string (http.request.uri.query)
Removes any parameter matching freqtype=...
Cleans up the leftover & if it was mid-string
Preserves all other parameters as-is
Leaves no trailing ampersands or double &&
bash/giftdetails?fund1=FN3200000&freqtype=once&ac=
Output:
bash/giftdetails?fund1=FN3200000&ac=
bash/giftdetails?fund1=FN3200000&freqtype=recur&freq=MON&amt1=20&ac=
Output:
bash/giftdetails?fund1=FN3200000&freq=MON&amt1=20&ac=
If you also want to:
remove ac=
remove empty query values
canonicalize fund parameters
…just tell me and I can extend the rule.
Nice, that’s a clear spec. Let’s handle all three things in one Cloudflare rule:
Remove freqtype
Remove ac
Rewrite freq=quarterly → freq=QTR
Keep fund1 and amt1 (and other examples you showed) intact
Using a Transform Rule → URL Rewrite → Dynamic is the cleanest way.
In Cloudflare Dashboard:
Rules → Transform Rules → URL Rewrite → Create rule
When incoming requests match:
Field: URL Path – Operator: equals – Value: /giftdetails
AND (optional but safer) add a second condition group:
Any of the following:
Query string contains freqtype=
Query string contains ac=
Query string contains freq=quarterly
Expression-wise, this is equivalent to:
text(http.request.uri.path eq "/giftdetails" and (contains(http.request.uri.query, "freqtype=") or contains(http.request.uri.query, "ac=") or contains(http.request.uri.query, "freq=quarterly")))
In Then → Rewrite URL → Dynamic, use this:
textconcat( "/giftdetails?fund1=", urlparam("fund1"), if( len(urlparam("freq")) > 0, concat( "&freq=", if( urlparam("freq") == "quarterly", "QTR", urlparam("freq") ) ), "" ), if( len(urlparam("amt1")) > 0, concat("&amt1=", urlparam("amt1")), "" ) )
Always starts the URL as:
/giftdetails?fund1=<value_of_fund1>
If a freq parameter is present:
If it equals "quarterly" → rewrites as freq=QTR
Otherwise keeps whatever it was (e.g., MON, YEAR, etc.)
If amt1 exists, it appends &amt1=<value_of_amt1>
It never includes:
freqtype
ac
Before:
/giftdetails?fund1=FN3200000&freqtype=once&ac=
fund1 = FN3200000
freq = empty
amt1 = empty
After (rewrite):
text/giftdetails?fund1=FN3200000
Before:
/giftdetails?fund1=FN3200000&freqtype=recur&freq=MON&amt1=20&ac=
fund1 = FN3200000
freq = MON
amt1 = 20
After (rewrite):
text/giftdetails?fund1=FN3200000&freq=MON&amt1=20
(freqtype and ac are dropped.)
Before:
/giftdetails?fund1=FN3200000&freqtype=recur&freq=quarterly&ac=
fund1 = FN3200000
freq = quarterly
amt1 = empty
After (rewrite):
text/giftdetails?fund1=FN3200000&freq=QTR
Exactly what you wanted.
If you later decide you also want to support amt2, fund2, etc., we can extend that expression in a structured way (without turning it into unreadable regex spaghetti).
Perfect — that’s an important distinction.
You want:
ac ONLY when it is emptyac= → remove
ac=&foo=bar → remove
ac not present → nothing to remove
ac=SOMETHING → keep it
freqtype alwaysfreq=quarterly → freq=QTRBelow is the updated Cloudflare Transform Rule → URL Rewrite → Dynamic expression that does exactly that.
Path equals /giftdetails
AND query contains one of:
freqtype=
ac=
freq=quarterly
textconcat( "/giftdetails?fund1=", urlparam("fund1"), /* freq (with quarterly → QTR rewrite) */ if( len(urlparam("freq")) > 0, concat( "&freq=", if( urlparam("freq") == "quarterly", "QTR", urlparam("freq") ) ), "" ), /* amt1 */ if( len(urlparam("amt1")) > 0, concat("&amt1=", urlparam("amt1")), "" ), /* ac: keep ONLY when nonempty */ if( and( urlparam_exists("ac"), len(urlparam("ac")) > 0 ), concat("&ac=", urlparam("ac")), "" ) )
freqtype alwaysfreq=quarterly → freq=QTRac=valueac= if emptyfund1
freq (rewritten if quarterly)
amt1
ac only if nonempty
bash/giftdetails?fund1=FN3200000&freqtype=once&ac=
AFTER
bash/giftdetails?fund1=FN3200000
bash/giftdetails?fund1=FN3200000&freqtype=recur&freq=MON&amt1=20&ac=
AFTER
bash/giftdetails?fund1=FN3200000&freq=MON&amt1=20
bash/giftdetails?fund1=FN3200000&freqtype=recur&freq=quarterly&ac=
AFTER
bash/giftdetails?fund1=FN3200000&freq=QTR
bash/giftdetails?fund1=FN3200000&freqtype=recur&freq=quarterly&ac=XYZ
AFTER
bash/giftdetails?fund1=FN3200000&freq=QTR&ac=XYZ
(ac is kept because value is nonempty)
I can output the exact JSON payload your dashboard expects.
var(--tw-content)