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?


Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

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