Best Place to 404 a Non-Matching Custom Query Var

Question

I’ve created a ‘tabbed’ layout on custom taxonomy archives on my website and successfully rewritten my permalinks so that visitors to mywebsite.com/player/player_name/tab_name see some conditional content as a child of the term. There’s currently about four tabs in action.

function wts_tab_rewrite_rule() {

    add_rewrite_rule( '^player/([^/]*)/(?!page)(?!feed)([^/]*)/?', 'index.php?player=$matches[1]&tab=$matches[2]', 'top' );
}

function wts_tab_query_var( $vars ) {

    array_push( $vars, 'tab' );
    return $vars;
}

However, it’s just come to my attention that a request to a non-existing tab resolves but is empty because it doesn’t meet the get_query_var() requirements. My question is, what is the best method to 404 any requests to a tab which I haven’t explicitly declared any content for, like mywebsite.com/player/player_name/tab_dont_exist? Should it happen at the point of redirect rule creation or at the point of content output?

0
Kevin Nugent 4 months 0 Answers 15 views 0

Leave an answer