Transform Rules > URL Rewrite > Dynamic


I’m trying to append a random string to the end of URLs with a set of paths and would like to know the expression to use for the dynamic query rewrite.

For example, I want to change: to to

If the path could be a wildcard, that would be nice, because this rewrite would apply to a set of incoming URL paths I’ve defined.

Thank you for your help.

You’ll need to use a concat() operator, e.g. concat(http.request.uri.path,"/","1234567") will result in requests to /path/ being rewritten to /path/1234567.

Thank you. When I tried that, it resulted in:

Strange. It’s working in my test lab with the dynamic rewrite concat(http.request.uri.path,"/","1234567").

Requests to are being received at origin to uri_path="/tubes.html/1234567.

Yeah, I get exactly this:

I’m assuming it’s not possible to use a random string expression in the Static rewrite to simply append the URL?

You could append the cf.ray_id field which is unique for each request.

That would work - how would I do that? I tried just putting the cf.ray_id into the static rewrite, but it returns post/cf.ray_id

You’d have to use dynamic with the following expression concat(http.request.uri.path, "/", cf.ray_id) :slightly_smiling_face:

1 Like

Same issue as before. I get:

If you need to rewrite path:
concat(http.request.uri.path, "/", cf.ray_id)

If you need to rewrite query:
concat(http.request.uri.query, "&", cf.ray_id)

1 Like

Thank you very much. Now I get:**&amp**;6d6c391b40c617b9-EWR

Is the amp part removable? Otherwise, I’ll work with it this way. Thanks again.

You can replace the query with just cf.ray_id (won’t have ampersand), but that will remove any existing query parameters - is that alright?

1 Like

Yes, that would be good. Code please :slight_smile:

When I use this: concat(http.request.uri.query, cf.ray_id)

I get this:

I apologize, but it is still not clear to me whether if you want to rewrite the path or the query and whether you want to replace or append. Could you tell which of the examples below describe what is is you want to achieve? Then I can post the solution :slightly_smiling_face:

Path replace:

Path append:

Query replace:

Query append:

1 Like

Thank you. It’s the last one I’m looking for – query append. When I used concat(http.request.uri.query, cf.ray_id) – it appended the cfid – but it did it twice. It repeats the cfid in the rewritten URL.

This should do query append. However, if the original query is empty, the rewritten query will end up ?&6d6c461d3222f019-EWR - there’s currently no way to avoid the ampersand afaik. Though most URL parsers should just ignore the empty parameter, so I suspect it won’t cause any issues.

1 Like

Okay, it’s just that it adds the cfid twice, but it will work:

That is… weird :thinking: I’m having no such issue while testing this on my end. Do you have multiple Transform Rules?