Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Long-standing issue with template route matching where final segment is optional #924

Open
PaulBaileyAtChan opened this issue Mar 2, 2021 · 0 comments
Labels

Comments

@PaulBaileyAtChan
Copy link

This report concerns a long-standing issue with template route matching. In at least some cases where the last segment of the route is an optional variable segment, the route fails to match when the optional segment is not present.

As a real use-case, I created the following route:

/about-us/global/photos/{setid:integer}

which is intended to match both when the final segment is present, and when it is absent. The "Require all variables?" option is turned off. In practice, the route matches only when the optional variable is present, and fails to match when it is absent. So:

/about-us/global/photos/123456 (matches)
/about-us/global/photos (doesn't match, but should)

An informal workaround for this situation has been in circulation for some years, and involves using a REGEX to define the previous segment, like this:

/about-us/global/{seg3:regex[(photos)]}/{setid:integer}

This modified route does match the URLs both with and without the optional last segment.

See the following discussion from several years ago on the official EE forums, which describes the REGEX hack, and suggests that it was provided by Ellis Labs as a workaround:

https://expressionengine.com/forums/topic/250610/problem-with-pagination-and-template-routes

The issue seems to persist in EE5.4.1. It's possible that it's fixed in EE6, but I haven't seen anything in the change logs which would be relevant. It would be nice if this glitch could finally be resolved.

@ops-andy ops-andy added enhancement New feature or request under review An EE team member is reviewing this issue labels Mar 25, 2021
@ops-andy ops-andy added enhancement: accepted and removed under review An EE team member is reviewing this issue labels Apr 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants