Page Rule Wildcard Shenanigans

#1

Rule:
www.example.com/-
301 to
/?foo=$1&bar=$2

Going to www.example.com/one-two works properly
->
/?foo=one&bar=two

Going to /one-two-three gets whacky
->
www.example.com/?foo=?foo=one&bar=two&bar=three

Not sure what it’s doing there… least-surprise would be
/?foo=one&bar=two-three
although if it’s greedy, three would be on its own. Is this WAI? Any clever way to only split on that first hyphen?

0 Likes

#2
www.example.com/*-*

obviously. Preview would help on a new post. :slight_smile:

1 Like

#3

Right. You’re only looking for one dash. So $2 will contain a dash and trigger the Page Rule again, which adds foo onto what you just redirected with two foos.

You may have to add multiple page rules, starting with a match for *-*-* if the most dashes you have is two. Then a second page rule for only one dash.

No guarantees this will work, but it should fix your current problem.

1 Like

#4

Ahh, I think I misunderstood the “Only one Page Rule will trigger per URL” text - so it’s doing the initial rewrite, and then it’s a new URL, so it runs again.

OK, thanks! Might have to do this with a “real” rewriting engine on the backend.

(Feature request: “one and done” checkbox on a rule so it’ll stop after processing once. :-D)

0 Likes

#5

To avoid further redirects, I’d suggest that a

/?foo*

page rule with some innocuous setting like IP Geolocation Header be placed before any

*-* page rules

1 Like

#6

Oh, duh. Yeah, that’s interesting - so it is greedy. That gives
/?foo=one-two&bar=three

Definitely workable with that. Thanks!

0 Likes

#7

I think One and Done generally works…except for a Forwarding URL which tells the browser to go to a different URL and try again. It’s very much like clicking a link on your website and you want Page Rules to execute again in that case.

1 Like