1

I have a handful of custom routes configured on this project like

'action/(?P<custom_id>[a-zA-Z][0-9]{6})/(?P<slug>.*)' => 'action/_member',

If I'm reading the docs correctly, then those need to change to become

'action/<custom_id:[a-zA-Z][0-9]{6}>/<entrySlug:{slug}.*>' => [
        'template' => 'action/_member'
    ],

but that gives me a template not found error when I hit localhost/action/L100582/&session=115

If I simplify the rule to become

action/steven' => [ 'template' => 'action/_member' ]

and hit, localhost/action/steven the template loads just fine.

I can't wrap my little head around what I'm missing.

1

The {slug} token you’re using there is going to get replaced with Craft’s slug pattern:

(?:[\p{L}\p{N}\p{M}\.\_\-]+)

Since that’s not an optional pattern, the resulting regex isn’t going to match your example URL, which doesn’t have a slug after the custom_id.

I’d recommend you use two separate routes that both point to the same template:

'action/<custom_id:[a-zA-Z][0-9]{6}>' => ['template' => 'action/_member'],
'action/<custom_id:[a-zA-Z][0-9]{6}>/<entrySlug:{slug}>' => ['template' => 'action/_member'],

(And just in case it wasn’t intentional, worth pointing out that the slug is going to be called entrySlug as opposed to slug with that route, which is another change from your Craft 2 route. Use <slug:{slug}> if you didn’t mean to change the name.)

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.