I want to have a custom 404 page that displays some additional information. I need to display the requested path that was not found and some pages suggestions based on that path (this is based on some internal logic that I don't think is relevant to my question).
Here is what I did:
I defined the default 404 page to be page-not-found
in admin/config/system/site-information
Then in my module I used hook_page_alter()
to define my pages suggestions (if drupal_get_http_headers("status")
is 404 Not Found
), and the request_uri()
to be shown on the 404 template page I created.
I have tried to save these values in different ways (session variable, ctools cache, everything I have tried leads to the same issue — see below).
In mymodule.module:
/**
* Implement hook_menu
* @return mixed
*/
function mymodule_menu() {
$items['page-not-found'] = array(
'title' => '',
'page callback' => 'mymodule_page_not_found',
'file' => 'inc/functions.inc',
'access callback' => TRUE,
);
return $items;
}
/**
* Implement hook_theme
*/
function mymodule_theme() {
return array(
'mymodule_page_not_found' => array(
'template' => 'templates/404',
),
);
}
In inc/functions.inc:
function mymodule_page_not_found() {
return theme('mymodule_page_not_found');
}
Problem is, if I request a non existing URL for example mysite.com/not-found-page-1
then request mysite.com/not-found-page-2
the information displayed on the 404 page template when I query the not-found-page-2 corresponds to the values I saved when requesting not-found-page-1.
Any idea why I always get the data of the previous query?