0

How do I handle a 404 redirect when let's say I have a template group called "about" and a template in that group called "leadership" but someone types about/leaderships instead of about/leadership?

Thanks.

  • What do you exactly want? Redirect to 404 or to "about/leadership"? – Robson Sobral Jun 4 '13 at 22:05
  • Redirect to 404. – mediapimp Jun 5 '13 at 13:07
1

The misspelt URL will fallback to your about/index template, so just put a simple...

{if segment_2}{redirect="404"}{/if}

... in that template.

This assumes you don't need to use any arbitrary segment values in that template. If you do, or if you want to use the index template for multiple urls, then instead you should use a combination of the require_entry parameter of the channel entries tag and the no_results conditional on the inside of the tag to perform the redirect.

|improve this answer|||||
1

Assuming that you want a general solution for redirecting misspelt and non-existant url_titles in your url, you need to use the require_entry parameter in combination with a no_results conditional as James Smith suggested. Here's a simple example:

{exp:channel:entries channel="projects" limit="1" require_entry="yes"}
   {if no_results}{redirect="404"}{/if}
{/exp:channel:entries}

Ryan Battles has written a good guide to ExpressionEngine 404 pages.

|improve this answer|||||
  • I have been using the method you posted but my channel entry tag is specifying an entry_id & require_entry does not seem to work when passing an entry_id. Is this expected behavior? – mediapimp Jun 5 '13 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.