I’m looking for a way to prevent the default behaviour (when you have a static page set as the site homepage or ‘frontpage’ (in settings>reading>front page displays );

I want the domain.com/ page to point here (as it does), but if I made a page home, which would otherwise live at domain.com/home WordPress automatically redirects to domain.com, and so there’s no way of visiting and staying on domain.com/home.

Does anyone have a clue how/where to do this? I’ve tried investigating php $_SERVER variables and attempting to alter rewrite rules, but I don’t find a rule therein that matches this situation reliably. (There is one rule to a page with the home page id, but then I cannot target this reliably (and I think it’s actually routing domain.com/ -> domain.com/home.)

To reiterate (and perhaps clarify), how does one make the wordpress ‘frontpage’ available at the domain root (as is default and working), but also at the page’s default permalink also…

2 Answers
2

The redirect is thanks to redirect_canonical() – we can simply swoop in with a filter and disable it for the front page:

function wpse_184163_disable_canonical_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', 'wpse_184163_disable_canonical_front_page' );

Now you can access the front page at the root and by it’s slug, no redirect.

Leave a Reply

Your email address will not be published. Required fields are marked *