Runway 301 Redirect collection - not working for Blog or Collections

  • This great post form the old forum by Shane Lenzen shows how we can set up a Collection called 301 Redirects. In this Collection you can set page redirections!


    https://forum.grabaperch.com/f…p-301-redirect-collection


    However, I find that the redirects only work on Pages, not when trying to redirect Blog items, or any other Collection item. I guess this is something to do with routing.


    Does anyone have any thoughts on how this could be overcome?

  • You need to trigger the error page for this to work. I think something like below would work


  • For my 404 page:


  • For my Post Page:


  • You'll want this to be at the top of your page, as the use_error_page function is basically just an convoluted includes function that sets the HTTP status to 404 as well

    Code
    1. $post = perch_blog_custom([
    2. 'filter' => 'postSlug',
    3. 'match' => 'eq',
    4. 'template' => 'detail',
    5. 'value' => ($slug = perch_get('slug'))
    6. ], true);
    7. if (!$post) {
    8. PerchSystem::use_error_page();
    9. }
    10. echo $post;

    It might be that you are using includes instead of perch_layout that it's including the header/footer again