Jump to content

Recommended Posts

Posted

I've made a temporary new page on a new template, I want to redirect all traffic to this for a while, whilst making the url just be "/", what's the cleanest way to do this please?

Posted

@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
Posted

Thanks @abdus that looks great. Actually I was in a rush and I decided I would have to accept having a "/holding-page" and just used $session->redirect() but if I get a chance I will definitely change to this so I can be on "/"

  • 4 months later...
Posted

I used this for a while and it was very helpful. But it isn't working for me anymore, has anything changed in a recent PW update that would stop the ready.php hook above working?

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
  • Recently Browsing   0 members

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