Boost Posted April 3, 2023 Posted April 3, 2023 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!
flydev Posted April 3, 2023 Posted April 3, 2023 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 : 2
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now