Rules of "transform rules" setup asking

I have a website https://bac.com/
I am looking for transform rules like if visitors type it then will be rewritten to https://bac.com/?w_id=123

and if visitors type https://bac.com/allproducts the automatic rewrite to adding ?w_id=123 at the end like https://bac.com/allproducts?w_id=123

I have read the official article for a long time and have done some experiments but failed, so I am looking for help from there, hopefully, someone can help me or some hints?

Thanks a lot…

If you’re looking to rewrite, that should be doable with Transform Rules → URL Rewrite → Query.

1 Like

Albert:

Thank you so much, looks great. but one more question is coming out, may you help?

I want to keep fixed content like https://bac.com/wp_admin and all following URLs without any changes.
like https://bac.com/wp_admin and such as bac.com/wp_admin/xxx all keep original URL, not need rewrite rule, how can I do this and keep your rewrite rule working together?

Thank you again.

Yes, that is possible :slightly_smiling_face:

Use the “Edit expression” button to switch to “manual”-mode:

Now edit the expression to include and not starts_with(http.request.uri.path, "/wp-admin"). The entire expression should now look like this:

The result is that any paths below /wp-admin will not have w_id=123 added to them.

I just wanted to mention that the current rewrite rule replaces the query string with w_id=123 instead of appending.

If you want to append w_id=123 to the current query string (therefore keeping existing parameters), change “Static” to “Dynamic” and set the value to concat (http.request.uri.query, "&w_id=123").

Though do note this will cause the query string to become ?&w_id=123 if the existing query string is empty - this should be treated as a valid query string but your URL parser may not like it.

I’m not sure I understand. Could you try rephrasing?

The URL Rewrite rule should look like this:

2 Likes

Hi Albert: the last one is not working,

Let me tell all exactly I need:

Running website bac.com looking for transform rules like if visitors not from one-third hostname: bbb.com then will be rewritten to https://bac.com/?w_id=123 and also after above rules applied if all coming traffic is https://bac.com/allproducts or https://bac.com/allproducts/xxx then want automatic rewrite to adding ?w_id=123 at the end like https://bac.com/allproducts?w_id=123 and https://bac.com/allproducts/product111?w_id=123

meanwhile want to keep fixed content like https://bac.com/wp-admin and all following URLs without any changes because it’s backend entries like https://bac.com/wp-admin and such as bac.com/wp-admin/xxx all keep original URL, not need a rewrite rule

how can I do it?

What happens when a user visits bbb.com? Are they redirected to bac.com? I need to understand your setup to make sure I provide the correct guidance :slightly_smiling_face:

This will also exclude any requests that have a Origin header containing bbb.com:

(
    http.host eq "bac.com"
and
    not starts_with (
        http.request.uri.path,
        "/wp-admin"
    )
and
    not http.request.headers["origin"][0] contains "bbb.com"
)
2 Likes

Thank you so much, after tested, your last rules looks great…

Happy new year to you.

@albert how to process below new rules:

and if I need when the end is ?wpam_id=x (x = any number) but excluds 5 then automatic rewritten to
?wpam_id=123

I ask this just test founded some ?wpam_id=x not automatic rewritten to ?wpam_id=123, how can process it?

also while you type bac.com directly browser will say:

This page isn’t working

bac.com redirected you too many times.

ERR_TOO_MANY_REDIRECTS


Now the rules like below:

We have a website: mysite.com, want to set up the below rule but tried several times not working, anyone can help to bring some hints?

question:

All coming traffic automatically adding ?wpam=1 at the URL end at the first time if no such end.

if the end already ?wpam=x (x is any number)then automaticlly covert ?wpam=x to ?wapm=1, but
?wpam=5 will remain original no need change.

After the first time converted then keep mysite.com access original URL.

I’m not sure that is possible to do with Transform Rules. URL Rewrites are made to do simple transformations that do not require much logic. I’d recommend you take a look at Cloudflare Workers - they will let you do this, and more :slightly_smiling_face:

thank you, I will take a look at workers…

worker is really hard to me, I need learn the transform rules again.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.