Incorrect URLs in segment_4 as tours/transit-tours/junk results in the same entry being display. How do I throw a 404 if the entry does not match the URL 100% or vice-versa, and is this the right approach for achieving this. Below is the transit-tours template that is current part of tours.group.
{if segment_2=="transit-tours" && segment_3 == ''}
{layout:stuff…} {exp:channel:entries channel="tours" limit="3" require_entry="yes" dynamic="no"} {title} <!– this shows the right entry page –> {/exp:channel:entries}
{if:else}
{exp:channel:entries channel="tours" limit="1" require_entry="yes" dynamic="no"} {layout:stuff…} Entry Page stuff. {/exp:channel:entries} {/if}
Appreciate any advice.
There are a whole lot of ways to approach URLs, routes and how to handle 404’s. So keep that in mind.
In the above, you wouldn’t use require_entry and a limit of 3. See the docs- that parameter tells EE that there should be an entry_id or a url_title in the url, meaning there should only be 1 and exactly 1 entry.
I personally don’t try to lock down every possible bad URL. If you keep an eye on inbound traffic and see something weird, I’d adjust to meet that. But otherwise, I go with locking down the most likely issues. If I know a page should never have more than 3 segments, I’d add in a
{if segment_4}{redirect="404"}{/if}
Does that help?
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.