Jump to content
Sign in to follow this  

Wire404Exception and PagePathHistory

Recommended Posts

Dear Communiy,

My template basic-page does have URL segments activated. The segments are used to handle a different URL for the files attached. If a file is not found a Wire404Exception() is thrown. Sadly PagePathHistory does not handle it correctly (in my opinion) and old URLs no longer are redirected to the new ones.


* Hook called upon 404 from ProcessPageView::pageNotFound
public function hookPageNotFound(HookEvent $event) {

$page = $event->arguments[0]; 

// If there is a page object set, then it means the 404 was triggered
// by the user not having access to it, or by the $page's template 
// throwing a 404 exception. In either case, we don't want to do a 
// redirect if there is a $page since any 404 is intentional there.
if($page && $page->id) return; 


The documentation makes sense here but is the opposite of the desired effect.

Only solution for my problem was to disable the if-Statement, is there a better way to do this?

Share this post

Link to post
Share on other sites

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Moritz Both
      For our PW project we use markup regions and, for one template, url segments. The documentation recommends throwing a new Wire404Exception() from the template when the code concludes that the url segments from the request are invalid, and so we do.
      However, the 404 page is not displayed properly. Viewing the page source in the browser we can see that the original, unmodified markup region contents from our _init.php file is prepended to the correct html output, messing the whole page up.
      Any advice is greatly appreciated.
    • By Thorsten
      I'm using "throw new Wire404Exception();"  in my template, it worked fine. After Migrating to an other server and Upgrading to PW 3.0.62 I got an Error "Class 'Wire404Exception' not found" . I spent the day yesterday unsuccessfully to understand the reason. Is there any reason, why PW can't find this class? The Exceptions.php in wire/core exists.
      I beg your pardon, if this topic should be discussed here yet - the search items 'Wire404Exception' and 'not found'  leed to many other results not related to the class itself.
    • By bfncs
      Hi everyone,
      I want to use the core module PagePathHistory in a Processwire instance with multi-language URLs/page names activated through the core module LanguageSupportPageNames. From looking at that old Post by Ryan I was pretty sure that it should work without any problems and was surprised that actually it doesn't.
      PagePathHistory only saves entries to it's DB table when the page name in the main language changes, not when any of the other language names change. Looking at the code this is no suprise as PagePathHistory only hooks Pages::moved(), Pages::renamed() and Pages::deleted(), none of which would be triggered by a change in a language page name.
      Starry-eyed I started to implement the missing language-awareness in the module, how hard can it be, eh?
      ...pretty quickly it turned out that this isn't that simple, so I decided to first ask for some help and guidance. Does anyone maybe already work out a solution for this particular problem or something similiar?
      The problem with the implementation is that after saving a page with changes to language names, there still has to be a means of accessing the old names. For the default language name this is pretty simple because it's saved as $page->namePrevious. For language names the module would have to deposit the original names for later to build the PagePathHistory-URLs. I've been looking through all hookable functions in core classes/modules but haven't found the best place to hook into to implement this functionality. Does anyone have an idea where this would be done best?
      Any help is appreciated. Thanks a lot in advance
    • By k07n
      I rebuilding site from another CMS and need to redirect some old pages to new ones.
      Old scheme of urls is site.com/index.php?id=123
      I have this in _init.php:
      $id = (int)$input->get->id; if ($id > 0) { $redirect_page = wire('pages')->get("parent=/tools/old2new/, template=old2new-redirect, name=$id"); if ($redirect_page instanceof NullPage) { throw new Wire404Exception(); } else { $url = $redirect_page->redirect_to->url . $redirect_page->param; wire('session')->redirect($url); } } So, Wire404Exception() -- throw me this:
      Fatal error: Exception: (in \www\site\templates\_init.php line 21) #0 \www\wire\core\TemplateFile.php(139): require() #1 [internal function]: TemplateFile->___render() #2 \www\wire\core\Wire.php(359): call_user_func_array(Array, Array) #3 \www\wire\core\Wire.php(317): Wire->runHooks('render', Array) #4 \www\wire\modules\PageRender.module(337): Wire->__call('render', Array) #5 \www\wire\modules\PageRender.module(337): TemplateFile->render() #6 [internal function]: PageRender->___renderPage(Object(HookEvent)) #7 \www\wire\core\Wire.php(359): call_user_func_array(Array, Array) #8 \www\wire\core\Wire.php(317): Wire->runHooks('renderPage', Array) #9 \www\wire\core\Wire.php(381): Wire->__call('renderPage', Array) #10 \www\wire\core\Wire.php(381): PageRender->renderPage(O in \www\index.php on line 216 But if I use exception from another template it working fine and render 404 page. 
      Please help to fix it and maybe some suggestion to "redirect" code?
  • Create New...