backes Posted December 7, 2016 Share Posted December 7, 2016 Hey folks, I'm working on a multi language site (german=default & english). I have the strange problem, that the 404 for inactive english pages won't work the way I expected it. For example: I enter the following kind of URL in the browser: myurl.com/en/mypageslug/ which is inactive in the backend. The systems shows me parts of the german page and the language switch is also active on german. If I switch to english it opens the 404 page, which is the right one. If I log the accessed pages, it shows me the 404 page as url - but the content in the frontend isn't the 404 page! I hope that someone understands the problem and can help me with this strange behavior. As one check I already wrote a little module to interfere in the pageloading - but it won't do what I want neither... <?php namespace ProcessWire; class ProcessLanguageError extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => __('LanguageError'), 'version' => '0.1.0', 'summary' => __('Throws 404 error if the current page is not accessible in the chosen language.'), 'autoload' => true, 'requires' => array('ProcessWire>=3.0.41', 'PHP>=5.6.10') ); } /** * */ public function init() { // frontend hooks $this->addHookAfter("Page::render", $this, 'hookReturnError'); } /** * @throws Wire404Exception */ public function hookReturnError() { if (!$this->page->viewable($this->user->language)) { $this->log('failure'); // the redirect show only a blank white page without any information... $this->session->redirect('http://www.google.de'); throw new Wire404Exception(); } else { $this->log('yeah baby'); return; } } public function validatePage($page) { if(!$page->viewable($this->user->language)) { $this->log('error404'); $this->session->redirect('http://google.de'); throw new Wire404Exception(); } return false; } } I appreciate any help!!! Thanks and greetings, Martin Link to comment Share on other sites More sharing options...
Zeka Posted December 7, 2016 Share Posted December 7, 2016 Hi @backes Is this behavior the same in cases when you logged in to admin panel and logged out? Link to comment Share on other sites More sharing options...
backes Posted December 7, 2016 Author Share Posted December 7, 2016 Hey @Zeka, thanks for your answer. Sadly it makes no difference... Link to comment Share on other sites More sharing options...
AndZyk Posted December 7, 2016 Share Posted December 7, 2016 Does your 404 exception event got thrown if you redirect the session before? I tested it locally and for me it doesn't get thrown. In my opinion you should either throw the exception or redirect. Regards, Andreas Link to comment Share on other sites More sharing options...
backes Posted December 7, 2016 Author Share Posted December 7, 2016 Thanks @AndZyk, yeah I know, currently the two lines were only there for testing, should have commented one out before posting! Link to comment Share on other sites More sharing options...
AndZyk Posted December 7, 2016 Share Posted December 7, 2016 Sorry, if I may not understand you correctly. But the way your module works right now, you would check if the 404 page is viewable in another language. Because if you try access a non-active page by default a 404 exception gets thrown and your module would hook into the 404 page. So it would be pointless to throw another 404 exception and log it, because that is the default behaviour. I am not quite sure, what you try to achieve, but if you want to customize your 404 page, you could just create an template and assign it to the 404 page. Link to comment Share on other sites More sharing options...
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