I’ve been searching through the forum, user guide and elsewhere but haven’t found a solution. I would like to serve a 404 if an invalid category is present in a requested URL.
sitename.com/templateGroup/category/categoryName/url_title
This was asked some time ago in this thread. A solution was offered
...
{if:elseif segment_2 =="category"}
<section id="books" class="category results">
{exp:channel:entries channel="books" limit="10"}
{categories}
{if category_url_title != "{segment_3}"}
{redirect="404"}
{/if}
{/categories}
{book_entry}
{/exp:channel:entries}
...another user, Boyink!, pointed out in this thread, that it won’t work if the first entry belongs to more than one category.
Is there a way to do this with built in EE or otherwise?
I’m sure there is a simple way to do it with php but I’m not sure how to execute it.
Custom query to pull all the categories for the channel or category group
Place them into an array
Conditional that states segment_3 must equal at least 1 item in the array.
If yes display the entries
If not redirect to 404
Any pointers or complete answers 😊 would be appreciated.