301 on missing Listings instead of 404?

Justin Alei's Avatar

Justin Alei

21 Feb, 2017 05:41 PM

Hi guys,
When working with listings, how do you setup a redirect instead of a 404 when a listing doesn't exist? The scenario is we want to automatically 301 redirect to the main blog page if someone tries to access an old post that has been deleted.

The {if no_results} tag doesn't work at all... in my example of a blog, this code would be on the listing template:

{exp:channel:entries channel="blog" limit="1" disable="categories|category_fields|member_data"}
{if no_results}{redirect="blog/index" status_code="301"}{/if}

But it doesn't appear this is being hit, I guess because the listing doesn't exist so Structure is 404ing before this code is being hit.

Is there a way to not automatically 404 so we can setup redirects instead?


  1. 1 Posted by Justin Alei on 03 Mar, 2017 05:36 PM

    Justin Alei's Avatar

    I'm guessing no response to this means it's not possible... is there any way we could add this as an option?


  2. Support Staff 2 Posted by Support on 17 May, 2017 01:03 PM

    Support's Avatar

    Structure doesn't control the main routing of EE when there is a 404. You can use an add-on like Detour Pro to setup 301 redirects for pages you delete but it's not automatic.

  3. Support closed this discussion on 17 May, 2017 01:03 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac