Redirect rules, How add parameter to URL

For Workers & Pages, what is the name of the domain?

why_is_this_required_cant_i_be_private_in_community.com

What is the issue or error you’re encountering

How do I add add parameter to URL in Redirect rules?

What are the steps to reproduce the issue?

I am trying to do the following in Rules > Redirect Rules:

If a URL complies with a certain filter expression, then I want to redirect it to the same URL, but with a specific parameter added.

I’m not sure how to use Dynamic expression in order to achieve this redirect. For example:

www.example.com/page/ should redirect to
www.example.com/page/?myparam=1

www.example.com/page/?search=hey should redirect to
www.example.com/page/?search=hey&myparam=1

You can use the http.request.uri.query field, but it might take some effort to handle working out if appending to an existing query string or not (or if the rules engine can do that automatically). Will try later if I have time.

If you are on a paid plan a Snippet is ideal for these sorts of cases, otherwise a Worker.

Thanks! Maybe I should have been clearer; I don’t really know how to use the Redirect dynamic expression field at all. I’m not seeing any examples anywhere.

Let’s say, for a simpler example, that I want to redirect to a different host, same path:

www.example.com/my-path/ redirect to
www.example_other/my-path/

Following your link, and looking at the other fields, it seems that I can get the path with

http.request.uri.path

So what I want is:

www.example_otherhttp.request.uri.path

But how do I add a string to a the value of the parameter? Is there a concatenate function? Can I use +? Do strings have to be in quotes. I’m missing something basic…

For redirecting example.com to example.org redirect all requests to…

concat("https://example.org", http.request.uri.path)

Or use a wildcard as here…

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