url rewriting – Query vars to return the homepage

Question

I would like to rewrite a path like example.com/foo to the “front” page (example.com).

So when I request example.com/foo the content shown should be that of example.com. Note, a redirect is NOT what I am looking for here.

I am trying to do this with the add_rewrite_rule() function but cant find the query vars to get the homepage

add_action( 'init', function() {
    add_rewrite_rule(
        '^foo/?$',
        'index.php?pagename=homepage',
        'top'
    );
});

I also tried index.php?pagename=/, index.php?page=front, index.php (no query vars) and a bunch of other combinations.

I just cant seem to find the query var to tell WordPress to load the homepage.

0
yevg 6 months 2022-01-28T18:31:15-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse