Orkun Posted September 12, 2018 Posted September 12, 2018 Hi Guys I don't know what I am doing wrong. I have a website with three languages. German (default), French and English. The homepage should be only visible on the default language. So i removed the check on french and english: But some children pages of home are active in the french and english language. Let's say I am on a children page in the french language, for example www.example.net/fr/lorem/. When I click on the Logo (linked to home) it redirects as expected to www.example.net/fr/ and outputs the content of 404 Error Page. What can I do, so that it redirects to the default version of home and not to a 404 Error site. I pasted this code to my home template but it only works when I am logged in: if(!$page->viewable($user->language)){ $session->redirect($page->localUrl($languages->getDefault())); } I have also tried to catch it with a Hook on ProcessPageView::pageNotFound: // hook on 404 page to render custom content or redirect $this->addHookAfter("ProcessPageView::pageNotFound", $this, "hookPageNotFound"); protected function hookPageNotFound(HookEvent $event) { $url = trim($event->arguments("url"),"/"); $page = $event->arguments("page"); // it seems when page is unpublished, we have no "url" from page not found hook if($page->is("unpublished")){ $url = $page->url; } // shortcut urls catch, if a page with "shortcut" matches requested url // we redirect to that page, sinmple and easy if($url) { wire('log')->save("test", $url); } } But www.example.net/fr/ doesn't trigger the hook... What I am doing wrong?
kixe Posted September 12, 2018 Posted September 12, 2018 make all languages viewable and put the following code in your home template if ($user->language->isDefault() === false) { $session->redirect($page->localUrl($languages->getDefault())); } 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