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

<pre><code>(?:[\p{L}\p{N}\p{M}\.\_\-]+)
</code></pre>

<p>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 <code>custom_id</code>.</p>

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

<pre class="lang-php prettyprint-override"><code>'action/&lt;custom_id:[a-zA-Z][0-9]{6}&gt;' =&gt; ['template' =&gt; 'action/_member'],
'action/&lt;custom_id:[a-zA-Z][0-9]{6}&gt;/&lt;entrySlug:{slug}&gt;' =&gt; ['template' =&gt; 'action/_member'],
</code></pre>

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

CC BY-SA 4.0
2019-03-29T09:06:10.897Z
2019-03-29T11:20:20.423Z
2019-03-29T11:20:20.423Z
Brandon Kelly
<p>I have a handful of custom routes configured on this project like</p>

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

<p>If I'm reading the docs correctly, then those need to change to become</p>

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

<p>but that gives me a template not found error when I hit <code>localhost/action/L100582/&amp;session=115</code></p>

<p>If I simplify the rule to become</p>

<p><code>action/steven' =&gt; [ 'template' =&gt; 'action/_member' ]</code></p>

<p>and hit, <code>localhost/action/steven</code> the template loads just fine.</p>

<p>I can't wrap my little head around what I'm missing.</p>

<url><routing>
Migrating custom routes from v2 to v3
# Migrating custom routes from v2 to v3

(Asked by: username_0 on 2019-03-28)

I have a handful of custom routes configured on this project like
'action/(?P[a-zA-Z][0-9]{6})/(?P.*)' => 'action/_member',
If I'm reading the docs correctly, then those need to change to become
'action//' => [
        '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.

**Tags:** url, routing


---

## 1 answers

### Answer by username_1 on 2019-03-29. Score: 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/' => ['template' => 'action/_member'],
'action//' => ['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  if you didn’t mean to change the name.)


---

