Jump to content

[SOLVED] How to redirect to homepage?


Boost
 Share

Recommended Posts

Hi,

I have this structure:

website.com/company/career
website.com/contact/thankyou

What I want to achieve is that if someone accesses the URLs "website.com/company/" or "website.com/contact/" she should be redirected to the homepage, since "/company" and "/contact" are just folders and there is nothing to see there.

Is there an easy way of doing that in PW? Maybe a different approach?

Thanks!

 

 

 

Link to comment
Share on other sites

Hello,

A simple way, by code, could be to redirect the user if the page is hidden. In the page's settings set the status `hidden` and then in the template(s) you can do:

<?php namespace ProcessWire;

// Template file for pages using the “basic-page” template

// the code below is an example of how to check if a page is hidden or unpublished
// and redirect to the homepage if it's the case.
// (/? hint > the check use a bitwise OR operator)
if ($page->is(Page::statusHidden | Page::statusUnpublished)) {
  $session->redirect($pages->get('/')->url); // redirect the user
}
?>

<div id="content">
  Contact or Company page
</div>

 

Another simple way, using template's settings, is to remove the view access of the guest role, see :

Clipboard01.thumb.png.44c8ef0b85869a203c115fd7c4721d1c.png

 

 

  • Like 2
Link to comment
Share on other sites

  • Boost changed the title to [SOLVED] How to redirect to homepage?

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