Homepage redirect to subpage and keeping subpage URL

Hey!

For a project with the following structure:

  • Works
  • About
  • Blog

I would like that when someone visits the homepage (mywebsite.com) it automatically redirects to Works (e.g. mywebsite.com is available for purchase - Sedo.com) but respecting works url instead of using the root one and displaying Works content.

The main reason for this case is analytics, so the client can see which pages are receiving visits, and since homepage displays works, would be great to automatically redirect there.

Is there any way to achieve this result? I can imagine I could simply write a redirect in the homepage template, but is there any better/cleaner solution?

I added a route to config and it works but not respecting the subpage full route.

'routes' => [
    [
      'pattern' => '/',
      'action'  => function () {
        return page('works');
      }
    ]
  ]

Instead of returning the page, you need to redirect to it

go('works');