base directories / URL

Is there a way to handle base directories for taxonomies that result in a 404. For example my URLs are:

http://skipology.com/category/
http://skipology.com/app/

Read More

but the taxonomies / base directories above result in 404. Can they be redirected to a taxonomy index page (which I may need to create) for example without impacting the child directory (post) or is there a better option. If so how? I suspect the answer lies in redirects but I’m not confident.

Related posts

3 comments

  1. You can manually create pages named category and app in admin under the Pages menu, and use a custom page template for each to list out taxonomy terms or whatever you need.

    EDIT – 301 redirect a request that matches the pagename rewrite to another page:

    function wpa_parse_query( $query ){
        if( isset( $query->query_vars['pagename'] )
            && 'apps' == $query->query_vars['pagename'] ){
                wp_redirect( home_url( '/other-page/' ), 301 );
                exit;
        }
    }
    add_action( 'parse_query', 'wpa_parse_query' );
    
  2. The answer by Milo above seems to potentially be a bit off the mark, because it doesn’t result in http://skipology.com/category/ being an actual page, but instead it just redirects to another page. I don’t know for sure so I’m just adding mine here as an alternative.

    If you are ok with a little bit of manual setup for this, this would be the simplest way to do this.

    • Create a page and give it the slug ‘category’
    • Create a page template and select if for the page you just created.

    The manual part of this is that you will have to create a separate page for each taxonomy. Each page just needs to use the same template, as long as you make the template correctly. You should be able to just detect the taxonomy dynamically and just use the same template on each one. The upside of this is that you don’t need to mess with any rewrite rules or manipulate the template hierarchy. You also make /category/ into an actual page rather than just redirecting to a different URL.

    Alternatively, if you want to make this completely automatic as if it were part of the native Template Hierarchy, you will need to add a rewrite rule for each taxonomy to catch those URI’s, then filter the template hierarchy to direct WordPress to the correct template. Take a look at this old answer of mine explaining how to filter the template hierarchy in different ways.

    It seems to me that if you go the route the rewrite rules, you’ll need to also add a custom query var. If this is the way you want to go, please let me know in a comment and I will update the answer with more details. I think the first method should suit you fine though.

  3. In the end I’ve found and tested some code that works in .htaccess…

    RedirectMatch 301 /app/?$ http://skipology.com/iphoneography-app-index/
    

    Just need to create something to redirect the other taxonomies to now.

Comments are closed.