Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

When I visit a page that does not exist, I expect to still see the primary and secondary links as on any other page.

But what I get is no navigation links in 404 page.

No navigation links on 404 pages

I have found a solution but i am happy if something else can fix this apart from a new module.

share|improve this question
1  
I Really expect other answers. –  Nikhil M Dec 19 '12 at 10:39
    
What do you mean by, "apart from a new module"? You can only resolve that writing code. –  kiamlaluno Dec 19 '12 at 13:49
    
@kiamlaluno i mean there will be some small tweaks i can make. –  Nikhil M Dec 19 '12 at 13:52
add comment

3 Answers

up vote 9 down vote accepted

So, here's another answer ;-)

You can do it by defining a page in a custom module.

Create a page for the category "Page not found" using hook_menu().

function MODULE_menu() {
  $items['page-not-found'] = array(
    'title' => '',
    'page callback' => 'MODULE_page_not_found',
    'access callback' => TRUE,
  );
  return $items;
}

function MODULE_page_not_found() {
  drupal_set_title('Page not found');
  $cust_err = "";
  $cust_err = $cust_err . "The requested page " . current_path() . " could not be found";
  return $cust_err;
}

In the callback function using current_path() will return the page which is producing the error.

Now that the page is created, go to admin > config > system > site-information, and enter page-not-found (same name as defined in hook_menu) under Default 404 (not found) page.

snap1

Sample screenshot of the page not found page:

snap2

It is clear that it contains all the navigation links, and also the page URL producing the error (very similar to the original page not found). And the module mentioned in the answer above by @Nikhil will output,

The requested page could not be found.

which does not contain the URL of the page ;-)

share|improve this answer
    
Are you sure i will get the navigation links in the page ? –  Nikhil M Dec 19 '12 at 14:25
1  
@NikhilM I've tested this and and the screenshots are real ;-) –  AjitS Dec 19 '12 at 14:25
    
nice solution, thank you. –  neok Jan 14 '13 at 9:43
add comment

There is a module to make this work 404 Navigation

On 404 Not Found error pages, Drupal will skip rendering of all the navigation links of your website for performance reasons*. Some of these include:

The "Primary links" block and any other menu links block. The Primary links and Secondary links of your theme. * Unless you have configured a "Default 404 (not found) page" on admin/config/system/site-information.

Also there is a Patch to fix this in D7.

In D8 See THIS Also THIS

share|improve this answer
add comment

There are also good module alternatives:

  • Search 404

    Instead of showing a standard "404 Page not found", this module performs a search on the keywords in the URL, e.g. if a user goes to http://example.com/does/not/exist, this module will do a search for "does not exist" and shows the result of the search instead of the 404 page. This should help retain visitors coming in from old URLs linked from other sites or from search indices.

  • Fast 404

    Drupal has expensive 404 errors. On an 'average' site with an 'average' module load, you can be looking at 60-100MB of memory being consumed on your server to deliver a 404. Consider a page with a bad .gif link and a missing .css file. That page will generate 2 404s along with the actual load of the page. You are most likely looking at 180MB of memory to server that page rather than the 60MB it should take.

share|improve this answer
    
Thanks i welcome your consideration. –  Nikhil M Dec 19 '12 at 16:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.