URL Forwarding: non-unique match wildcard redirect

Hi guys,

Not sure if the behavior observed for a URL forwarding rule is as expected, so I’m sharing the case in an attempt to clarify it.

Thanks in advance!


:gear: Page Rule settings

Basically, this Page Rule acts on URLs that contain /@/ (witch I’ll call “delimiter”) keeping the path before ($1) and discarding everything after ($2) it. The delimiter itself is removed as well.

Forwarding URL

Type 302 - Temporary Redirect
Source https://example.com/*/@/*
Destination https://example.com/$1

:white_check_mark: Example A: Unique match

Source link A contains 1 occurrence of the delimiter:

Example A details

Source link

  • https://example.com/unique/@/matching

Redirect chain

  1. [302] https://example.com/{unique}/@/{matching}
  2. [200] https://example.com/unique

The {brackets} are used to highlight matches $1 and $2 in redirects

Matched wildcards

Redirect #1

  • $1 (forwarded) = unique
  • $2 (discarded): = matching

:warning: Example B: Non-unique match

Source link B contains 2 occurrences of the delimiter:

Example B details

Source link

  • https://example.com/non/@/unique/@/matching

Redirect chain

  1. [302] https://example.com/{non/@/unique}/@/{matching}
  2. [302] https://example.com/{non}/@/{unique}
  3. [200] https://example.com/non

The {brackets} are used to highlight matches $1 and $2 in redirects

Matched wildcards

Redirect #1

  • $1 (forwarded) = non/@/unique
  • $2 (discarded) = matching

Redirect #2

  • $1 (forwarded) = non
  • $2 (discarded) = unique

:interrobang: Behavior: Current vs. Expected

In Example B the first occurrence of /@/ was ignored by Redirect #1 and became part of its $1:

Current redirect chain

  1. [302] https://example.com/{non/@/unique}/@/{matching}
  2. [302] https://example.com/{non}/@/{unique}
  3. [200] https://example.com/non

The {brackets} are used to highlight matches $1 and $2 in redirects

So current behavior requires an extra redirect in the chain compared to expected:

Expected redirect chain

  1. [302] https://example.com/{non}/@/{unique/@/matching}
  2. [200] https://example.com/non

The {brackets} are used to highlight matches $1 and $2 in redirects


:paperclip: Readings taken


I’m not a developer/programmer, so I’m sorry if I was wrong about any term or concept.
This topic has been edited a few times to make it more succinct and easy to understand.

1 Like

I opened a support ticked to clarify this issue. Here’s a summary of the request and response:


Request


Response

The first wildcard in your page rule matches any character after https://example.com/ so it matches non/@/unique/@/matching going to the end of the string or URL.

To continue matching your page rule then it searches for */@/ but it goes from where it left (the end of the URL) to the left until it finds the match so $1 is set to non/@/unique and that is why it redirects to https://example.com/non/@/unique.

The same page rule is applied to https://example.com/non/@/unique and now it redirects to https://example.com/non.

Unfortunately this is expected behavior and you will have to find a different pattern in your URL to create your page rule.

I am not sure what is the problem you are trying to solve but here is another feature that might be related to what you are looking for: Using Page Rules to Re-Write Host Headers but this is an Enterprise feature.


:pray: Thank you very much to Salvador, from the Support Team, who dedicated time - as well as patience - to understand and clarify this issue.

2 Likes