1

I'm using a static page for my Front page. It is a custom template. On my custom template I am using WP_Query() to show a list of posts. I also have a custom taxonomy called "Types" that I use on my posts.

I am using add_rewrite_rule() to redirect http://example.com/types/example to my static front page. My rewrite looks like:

add_rewrite_rule('^types/([^/]*)/?', 'index.php?page_id=24&type=$matches[1]', 'top'); 

The rewrite "works", but it redirects to http://example.com. If I disable the static front page in wordpress, the redirect works perfectly.

Is it possible to use add_rewrite_rule() with a wordpress static front page?

  • 1
    Not sure if I understand your problem. Note that redirect is not the same that rewrite. A redirection means that the user is taken from one URL to another; the user enter a URL in the browser and when he/she is redirected the URL in the browser will change. The rewrite doesn't change the URL that the user sees in the browser but it is internally rewritten to something else server-side. Can you explain again what you are trying to do and where do you have the problem? – cybmeta Apr 23 '15 at 19:39
  • I'll try to keep it simple. How can I use a permalink like example.com/types/example on my static front page? If I visit example.com/types/example my taxonomy.php template is used, which I believe is normal behaviour in wordpress. I could use something like example.com/?type=example, but I'd like to avoid that if possible. I hope that makes a little more sense. – Ryan M Apr 23 '15 at 19:49
  • 1
    I think you want a template filter, not a rewrite rule. – Milo Apr 23 '15 at 20:08
  • The template filter did the trick. Now when i visit /types/example, my static front page is used instead of the archives template (which was taxonomy.php). It's not an ideal solution but it works. Thanks for the suggestions @Milo – Ryan M Apr 24 '15 at 13:10
1

Found the solution in this thread: How to prevent the default home rewrite to a static page

Just disable canonical redirect for front page:

function disable_canonical_redirect_for_front_page( $redirect ) {
    if ( is_page() && $front_page = get_option( 'page_on_front' ) ) {
        if ( is_page( $front_page ) )
            $redirect = false;
    }

    return $redirect;
}
add_filter( 'redirect_canonical', 'disable_canonical_redirect_for_front_page' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.