You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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:
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.
The text was updated successfully, but these errors were encountered:
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.
The text was updated successfully, but these errors were encountered: