• Hi All,

    I have an extra feed of things that I want to offer along with posts and comments. The actual script that generates this feed is here:

    http://harrymetcalfe.com/wp-content/themes/hemingway/zeitgeist/feed.php

    That, however, is horrid. I want to have that feed appear at this URI:

    http://harrymetcalfe.com/zeitgeist/feed

    After a futile hour messing with .htaccess, I figured it would be better to use template_redirect, so I added the following:

    add_action('template_redirect', 'do_template_redirect');
    
    function do_template_redirect()
    {
       global $wp_query;
    
       if($wp_query->query_vars['pagename'] == 'zeitgeist' && $wp_query->query_vars['feed'] == 'feed')
       {
          include TEMPLATEPATH . "/zeitgeist/feed.php";
          exit;
       }
    }

    In Firefox, http://harrymetcalfe.com/zeitgeist/feed works as expected. It doesn’t work anywhere else, however — my feed reader, wget and Google Reader all get a 404 when they access that URI.

    Any clues?

Viewing 3 replies - 1 through 3 (of 3 total)
  • treehousetim

    (@treehousetim)

    I just dealt with this myself.

    You need to do something with a filter.

    For example, I was working with http://www.lightafire.net to add related pages.

    The url of these is http://www.lightafire.net/related/achievement/

    but that /related url does not exist. I coded a function that handled it using template_redirect, but a 404 was being sent before getting to that function.

    What ended up working for me is a simple bit of code – not sure if this will help you or not, but I hope so.

    add_filter( 'query_vars', 'addRelated' );
    function addRelated( $qv )
    {
        $vars[] = 'related';
    }

    hope this helps!

    treehousetim

    (@treehousetim)

    ignore that – I’m a moron.

    treehousetim

    (@treehousetim)

    ok… here’s what you need

    add_filter( 'query_vars', 'addRelated' );
    function addRelated( $qv )
    {
        $rq = trim ( $_SERVER['REQUEST_URI'], '/' );
    
        if ( $rq == 'zeitgeist/feed' )
        {
            return;
        }
        return $vars;
    }

    This means you’ll need to use this same if in your template_redirect handler.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Strange 404 error using template_redirect’ is closed to new replies.