We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Incorrect URLs still shows Entry. Week 2 Newbie.

How Do I?

NicholasD's avatar
NicholasD
5 posts
6 years ago
NicholasD's avatar NicholasD

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.

       
Robin Sowell's avatar
Robin Sowell
13,158 posts
6 years ago
Robin Sowell's avatar Robin Sowell

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?

       
NicholasD's avatar
NicholasD
5 posts
6 years ago
NicholasD's avatar NicholasD

Thank you Robin. Works like magic.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.