<p>I did something similar for a site that showcased projects.</p>

<p>In the top of my entry page, I had code like this:</p>

<pre><code>{% set entrySlug = craft.app.request.getSegment(2) %}
{% set entry = craft.entries.section('services').slug(entrySlug).one() %}

{% if entry is not defined or entry is null %}
    {% exit 404 %}
{% endit %}
</code></pre>

<p>And then I've got two routes:</p>

<p><code>services/&lt;slug&gt;/*</code> which routes to <code>services/_entry</code></p>

<p><code>services/&lt;slug&gt;</code> which routes to <code>services/_entry</code></p>

<p>Might not need both, but for me, when I didn't have both, I'd get a 500 error when the second segment was broken.</p>

CC BY-SA 4.0
2020-02-13T17:08:18.273Z
2020-02-13T17:08:18.273Z
SamC
<p>I am trying to configure my routes so that the last segment of the URL is ignored and can be used as parameter in the twig file.</p>

<p>for example, the following URL should ignore the city-segment</p>

<pre><code>/services/name-of-the-service/city
</code></pre>

<p>and should be routed to</p>

<pre><code>/services/name-of-the-service
</code></pre>

<p>I have currenty set up the following routing-rule</p>

<pre><code>'services/&lt;service:{slug}&gt;/&lt;city:{slug}&gt;' =&gt; 'service/&lt;service&gt;'
</code></pre>

<p>Which results into a 404 and says 
<strong>Unable to resolve the request "services/name-of-the-service".</strong>
Which is the exactly the URL that I want to get parsed...</p>

<p>When I am trying to route to the template</p>

<pre><code>'services/&lt;service:{slug}&gt;/&lt;city:{slug}&gt;' =&gt;  ['template' =&gt; 'services/_entry']
</code></pre>

<p>Which seems to load the correct template but the entry can not be parsed...</p>

<p>Any ideas how to solve / work around this problem?</p>

<routing><segments>
Routing: ignoring a segment from the URL
# Routing: ignoring a segment from the URL

(Asked by: username_0 on 2020-02-13)

I am trying to configure my routes so that the last segment of the URL is ignored and can be used as parameter in the twig file.
for example, the following URL should ignore the city-segment
/services/name-of-the-service/city

and should be routed to
/services/name-of-the-service

I have currenty set up the following routing-rule
'services//' => 'service/'

Which results into a 404 and says 
Unable to resolve the request "services/name-of-the-service".
Which is the exactly the URL that I want to get parsed...
When I am trying to route to the template
'services//' =>  ['template' => 'services/_entry']

Which seems to load the correct template but the entry can not be parsed...
Any ideas how to solve / work around this problem?

**Tags:** routing, segments


---

## 1 answers

### Answer by username_1 on 2020-02-13. Score: 2 | Accepted answer

I did something similar for a site that showcased projects.
In the top of my entry page, I had code like this:
{% set entrySlug = craft.app.request.getSegment(2) %}
{% set entry = craft.entries.section('services').slug(entrySlug).one() %}

{% if entry is not defined or entry is null %}
    {% exit 404 %}
{% endit %}

And then I've got two routes:
services//* which routes to services/_entry
services/ which routes to services/_entry
Might not need both, but for me, when I didn't have both, I'd get a 500 error when the second segment was broken.


---

