4

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...

4
  • Why is it so important for the page to be called /home!? You could try making a static page in the root folder /home/index.php if you really need it?
    – Bysander
    Commented Apr 14, 2015 at 11:37
  • 1
    please explain the reason for doing anything like that? why don't you just call your home page something else? Commented Apr 14, 2015 at 11:37
  • It doesn't matter what the home page is called. We've a specific use case where we need to be able to view the home page both at domain.com and domain.com/home but yet discern between the two for some functionality.
    – josh
    Commented Apr 14, 2015 at 12:57
  • I realise i could set up two home pages... home and home2 and achieve this by setting home2 as the frontpage, but that's not really maintainable
    – josh
    Commented Apr 14, 2015 at 12:58

2 Answers 2

7

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.

1
  • Perfect! I knew there'd be a hook somewhere, but all my googlings didn't turn up anything. Thanks so much, works perfectly.
    – josh
    Commented Apr 14, 2015 at 16:25
0

If i have understood you correctly you just need your domain.com/home to display your homepage too? Just create this in a folder called home in the same folder as your /wp-content etc

Name it index.php

?php
    header("Location: http://domain.com");
    exit();
?>
3
  • The problem is getting that without the URL changing (so domain.com/home is still displayed. I hadn't thought of this though... It doesn't achieve exactly what I'm after, but could be a good jump off point. Thanks
    – josh
    Commented Apr 14, 2015 at 12:52
  • I wouldn't really be sure how to do it without the url changing - unless perhaps you changed the header to just include and point it at your home.php ?
    – Bysander
    Commented Apr 14, 2015 at 13:17
  • Yeh, i was thinking of that. A query for the page that is front_page, and then set that as post and include should replicate everything. Only thing is if the page is called something other than 'home', which could be. It becomes untenable.
    – josh
    Commented Apr 14, 2015 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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