Jump to content

Best way to redirect all traffic to a page?


cjx2240
 Share

Recommended Posts

@cjx2240, I'm not sure if this is the best way, but hey it works.

Put this in your /site/ready.php

wire()->addHookBefore('Page::render', function (HookEvent $e) {
    // requested page (not the one being rendered)
    $page = $e->page;

    // skip admin pages
    if (strpos($e->input->url, $e->config->urls->admin) === 0) return;

    // force redirect to homepage
    if ($page->id != 1)  {
        $e->session->redirect('/');
    }
});

And in your home template, put this at the beginning

<?php namespace ProcessWire;

$splashPage = $pages->get(1353);
echo $splashPage->render();
return $this->halt();

 

  • Like 4
Link to comment
Share on other sites

  • 4 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...