Answers.Body: <p>Take a look at the <a href="http://buildwithcraft.com/docs/templating/exit" rel="nofollow">{% exit %}</a> tag. You should be able to do something very similar, since your search will return no results if the entry type does not exist.</p>
  
  <pre><code>{% set entries = craft.entries.type(craft.request.getSegment(3)).relatedTo(category) %}
  
  {% if not entries %}
      {% exit 404 %}
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-04T20:01:54.617Z
Answers.LastActivityDate: 2015-08-04T20:01:54.617Z
Answers.UserDisplayName: Aaron Berkowitz
Body: <p>So i added a route to a template that shows entries by entry types.
  the way the template does it is by taking the last segment of the url, and using it as an entry slug for this filter:
  <code>craft.entries.type(craft.request.getSegment(3)).relatedTo(category)</code>
  So, how can i check if the string in the segment matches any of the entry types in that section, and if not - redirect to 404 page?</p>
  
Tags: <routes><filter><entry-type><category><segments>
Title: check if a route segment matches a section entry type
ThreadText: # check if a route segment matches a section entry type
  
  (Asked by: username_0 on 2015-08-04)
  
  So i added a route to a template that shows entries by entry types.
  the way the template does it is by taking the last segment of the url, and using it as an entry slug for this filter:
  `craft.entries.type(craft.request.getSegment(3)).relatedTo(category)`
  So, how can i check if the string in the segment matches any of the entry types in that section, and if not - redirect to 404 page?
  
  **Tags:** routes, filter, entry-type, category, segments
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-08-04. Score: 3 | Accepted answer
  
  Take a look at the [{% exit %}](http://buildwithcraft.com/docs/templating/exit) tag. You should be able to do something very similar, since your search will return no results if the entry type does not exist.
  
  ```
  {% set entries = craft.entries.type(craft.request.getSegment(3)).relatedTo(category) %}
  
  {% if not entries %}
      {% exit 404 %}
  {% endif %}
  
  ```
  
  
  ---
  
  