Hi!
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?