<p>The reason you're getting a 404 is because Craft isn't even hitting your <code>help/_entry.html</code> template. Because there's no entry matching the URI <code>/help/asdf</code>, the template will never render and the request will go straight to 404.</p>

<p>The solution is to create a <a href="https://craftcms.com/docs/routing#dynamic-routes" rel="nofollow">dynamic route</a> matching your section's URL format (i.e. <code>help/&lt;slug&gt;</code>), and point it to the same template.</p>

<p>This works, because whenever Craft can't match a URI to an entry or category, it'll then try to render any dynamic route matching the URI's format (for a deeper understanding of how Craft manages routes and requests, I'd recommend looking at the <a href="https://craftcms.com/docs/routing" rel="nofollow">the official docs' page on routing</a>).</p>

CC BY-SA 3.0
2016-10-11T14:53:17.457Z
Thanks so much @Mats. I'm migrating an EE site and in the old site, when a user hit **/help/** I would simply check for value in seg2, and if didn't exist, would specify a specific Entry_ID in the EE Entries tag. That would always display whatever Entry the client wanted at the **/help/** index.

So what I'm now doing in Craft (found in another question here) in these simple Sections is having help/index and help/_entry, where help/index just has a 301 redirect to **/help/valid-index-slug-wanted-by-client**

A bit of a hack but accomplishes what the client wants.
Shane Robinson
CC BY-SA 3.0
2016-10-04T12:01:31.383Z
2016-10-04T12:01:31.383Z
Mats Mikkel Rummelhoff
<p>All the documentation, and answers here say this should work... But it returns the 404 instead of redirecting and I can't figure out why?</p>

<ul>
<li>Section: Structure = help </li>
<li>Entry URL Format: Top-Level Entries =
help/{slug} </li>
<li>Entry URL Format: Nested Entries = help/{slug} </li>
<li>Entry 'sTemplate = help/_entry</li>
</ul>

<p>Top line of the "help/_entry.html" template contains</p>

<pre><code>{% if entry is not defined %}
    {% redirect "/help/welcome-to-help" 301 %}
{% endif %}
</code></pre>

<p>where "welcome-to-help" is an Entry slug in the Help Section.</p>

<p>If I hit "example.com/help/welcome-to-help/" <em>(or any other valid Slug)</em>, everything works fine. But if I hit "example.com/help/asdf/" it returns the 404 instead of redirecting. </p>

<p>Am at a loss at this point??</p>

<entry><redirect><routing><404>
Redirecting "if entry is not defined" returns 404 instead
# Redirecting "if entry is not defined" returns 404 instead

(Asked by: username_0 on 2016-10-04)

All the documentation, and answers here say this should work... But it returns the 404 instead of redirecting and I can't figure out why?

Section: Structure = help 
Entry URL Format: Top-Level Entries =
help/{slug} 
Entry URL Format: Nested Entries = help/{slug} 
Entry 'sTemplate = help/_entry

Top line of the "help/_entry.html" template contains
{% if entry is not defined %}
    {% redirect "/help/welcome-to-help" 301 %}
{% endif %}

where "welcome-to-help" is an Entry slug in the Help Section.
If I hit "example.com/help/welcome-to-help/" (or any other valid Slug), everything works fine. But if I hit "example.com/help/asdf/" it returns the 404 instead of redirecting. 
Am at a loss at this point??

**Tags:** entry, redirect, routing, 404


---

## 1 answers

### Answer by username_1 on 2016-10-04. Score: 3 | Accepted answer

The reason you're getting a 404 is because Craft isn't even hitting your `help/_entry.html` template. Because there's no entry matching the URI `/help/asdf`, the template will never render and the request will go straight to 404.

The solution is to create a [dynamic route](https://craftcms.com/docs/routing#dynamic-routes) matching your section's URL format (i.e. `help/`), and point it to the same template.

This works, because whenever Craft can't match a URI to an entry or category, it'll then try to render any dynamic route matching the URI's format (for a deeper understanding of how Craft manages routes and requests, I'd recommend looking at the [the official docs' page on routing](https://craftcms.com/docs/routing)).

> **Comments:**
> **username_0**: Thanks so much @Mats. I'm migrating an EE site and in the old site, when a user hit **/help/** I would simply check for value in seg2, and if didn't exist, would specify a specific Entry_ID in the EE Entries tag. That would always display whatever Entry the client wanted at the **/help/** index.  So what I'm now doing in Craft (found in another question here) in these simple Sections is having help/index and help/_entry, where help/index just has a 301 redirect to **/help/valid-index-slug-wanted-by-client**  A bit of a hack but accomplishes what the client wants.  

---

