Redirect Rules with path forwarded to query variable

My current Page Rule takes all q-domain-com/123aab requests and 301 forwards them to www-domain-com/page.php?code=123aab . It takes the 123aab from the original request and redirects to the page.php page with the query string ?q=123aab.

Original Page Rule =
q-domain-com/*
Forwarding URL (Status Code: 301 - Permanent Redirect, Url: https://www-domain-com/page.php?q=$1)

I’m having difficulty getting this into the new Redirect Rules.

I’ve gotten up to:

  1. Custom Filter Expression
  2. URI Full contains https://q-domain-com/
  3. URL Redirect Static: https://www-domain-com/page.php?q=${path}

However, I’m assuming that would need to be a Dynamic URL redirect, and the Dynamic URL redirect with the above parameter does not save. I get an error from CF sayng target_url should be either value or expression (Code: 20083).

I also tried Dynamic = https://www.domain.com/page.php?q=$1, and I got the same error.

I was looking for the Expression Builder in the “Then…” section of the Redirect Rules, but I could not get that to show up!

Can you offer any guidance?

I got this working with a Worker. However, it would look cleaner if it was just a rule. Possible to make this a Redirect Rule? Or, is worker the only way to go?

Create the following Redirect Rule with custom filter expression:

Field = Hostname
Operator = contains
Value = domain1.com

Then

Type = Dynamic
Expression = concat("https://www.domain2.com/page.php?q=", substring(http.request.uri.path, 1))
Status code = 301
Preserve query string = OFF/unchecked

1 Like

Strangely, I don’t have the Expression editor for the “Then” part of the page. I’m on the free plan, maybe that’s why.

Regardless, the worker is working well for me. Strange that it’s not easy and straight-forward anymore!

Make sure you’re on the right page. Click on Rules, the menu will expand, then click on Redirect Rules as shown in the screenshot below:

P.S. All plans come with Redirect Rules.

Is there supposed to be another “Expression” box below the “Then” inputs?

Above is my original reply to you. According to your screenshot, some of your settings are wrong. Please refer to my instructions once again. It then should solve your original problem.

Thank you! I guess I just expected the expression editor to be that grey color that it normally is. I was looking at the page too quickly. Thank you for your help!

1 Like

Any time :slightly_smiling_face:

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