How to redirect page not found ?

Post Reply
affiliate
Ssr. Bludit
Posts: 14
Joined: Mon Jul 04, 2022 1:25 pm
Been thanked: 2 times

Hello,
i just would like to find a way to redirect page not found to another url.

I explain why.
If you buy an expired domain, domain will have links useful for seo. Sometimes, it will be a link to mydomain.com/page1 and when i recreate the website, maybe i will not have such url.
The power of the link will then be lost.
If i can do a redirect 301 of this page (so with my new installation it corresponds to a 404 page) to the main page of my site or a specific page, the seo power will be sent to these page.

As i work quite a lot with expired domains, this is something i really need to do. Some help ?
affiliate
Ssr. Bludit
Posts: 14
Joined: Mon Jul 04, 2022 1:25 pm
Been thanked: 2 times

actually i found a quick and dirty solution :

open file functions.php and add header with the page you want to redirect to.

// Generate the page 404 Not found
function buildErrorPage() {
global $site;
global $L;

header('Location: https://www.example.com/');
exit;

try {
$pageNotFoundKey = $site->pageNotFound();
$pageNotFound = New Page($pageNotFoundKey);
} catch (Exception $e) {
$pageNotFound = New Page(false);
$pageNotFound->setField('title', $L->get('page-not-found'));
$pageNotFound->setField('content', $L->get('page-not-found-content'));
$pageNotFound->setField('username', 'admin');
}

return $pageNotFound;
}
Post Reply