<p>I have a section where most entries have a category assigned to them, but a few ones have no category at all.</p>

<p>I need help how to connect these entries' URLs to my entry template.</p>

<p>So far I used a route to catch these cases and assign them to the entry template:</p>

<p>"Route URLs like <code>section/slug</code> to template <code>/section/_entry</code>."</p>

<p>Then I realised that this also catches all entries that have a category, so both these URLs would be valid: <code>/section/category1/slug1</code> and <code>/section/slug1</code></p>

<p>But all entries with a category assigned to them should raise a 404 if their category is missing from the URL.</p>

<p>This looks like a common scenario, but so far I only found a solution where those entries are <a href="https://craftcms.stackexchange.com/questions/1523/is-there-any-way-of-specifying-a-default-category-for-a-category-field">given a default category</a>.</p>

<p>How can I handle my case?</p>

CC BY-SA 4.0
2018-10-30T10:21:35.427Z
Do you use custom routing or entry/section routing? I don't really understand your issue to be honest because your routes are set in the section settings there is only one route for each entry. An entry doesn't have multiple different routes
Robin Schambach
CC BY-SA 4.0
2018-11-20T00:02:33.613Z
@Robin, I'm using entry/section routing. The URI entry is "{category.inReverse().one().uri}/{slug}" (as some entries have sub-categories), the template entry "mysection/_entry". I also have a custom route for those entries without a category: "mysection/slug" which I route to a template that redirects depending on the presence of a category.
Crafty Cat
<templating><category>
How to handle URLs of entries with no category?
# How to handle URLs of entries with no category?

(Asked by: username_0 on 2018-10-30)

I have a section where most entries have a category assigned to them, but a few ones have no category at all.

I need help how to connect these entries' URLs to my entry template.

So far I used a route to catch these cases and assign them to the entry template:

"Route URLs like `section/slug` to template `/section/_entry`."

Then I realised that this also catches all entries that have a category, so both these URLs would be valid: `/section/category1/slug1` and `/section/slug1`

But all entries with a category assigned to them should raise a 404 if their category is missing from the URL.

This looks like a common scenario, but so far I only found a solution where those entries are [given a default category](https://craftcms.stackexchange.com/questions/1523/is-there-any-way-of-specifying-a-default-category-for-a-category-field).

How can I handle my case?

**Tags:** templating, category

> **Comments:**
> **username_1**: Do you use custom routing or entry/section routing? I don't really understand your issue to be honest because your routes are set in the section settings there is only one route for each entry. An entry doesn't have multiple different routes  
> **username_0**: @Robin, I'm using entry/section routing. The URI entry is "{category.inReverse().one().uri}/{slug}" (as some entries have sub-categories), the template entry "mysection/_entry". I also have a custom route for those entries without a category: "mysection/slug" which I route to a template that redirects depending on the presence of a category.  

---

## 0 answers

