When Drupal 6.x dev always returns "page not found"... pages can still be found

Submitted by Frederic Marand on

A problem with the yet unreleased versions of Drupal 6 is that in some cases Drupal all of a sudden seems to lose all of its paths. In my case it happened when working on a port of an OSInet module from the Drupal 4.7 to Drupal 6 API.

A symptom of the problem can be seen by checking the menu_router table and finding it to be empty, although it should contain the default site navigation.

Before reinstalling, a quick hack/fix can return the site to a better behaviour: since Drupal knows how to install itself, how about asking it to regenerate the menu_router table ? Luckily, there's a function which does just that: menu_rebuild.

So just edit index.php at the root of your Drupal install, just like this:

<?php// [...]drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);menu_rebuild(); // use just oncedie();          // use just once$return = menu_execute_active_handler();// [...]?>

Now invoke any page on the site, just once, then remove the two added lines, and your menu should return to normal.

Jonathan (not verified)

Tue, 2008-01-08 22:24

Thanks, this advice was a lifesaver. My problem happened after Drupal 6 RC1 was working well for a while but then I tried to use the views module and the site died.

Stefan (not verified)

Wed, 2008-02-20 21:57

Thanks for this one, that really helped my - and you might guess I'm not a php expert :)

Anonymous (not verified)

Fri, 2008-03-21 12:56

Hi. Before finding your method my way was to copy menu_router content again. Have you found the reason the table is emptied? On my local machine the module I am writing works fine. On the production machine it just empties the table... I am puzzled.
Thanks

It happened when I tried to write a code to add an action and enabled my module for the 1st time

I cannot see any connection between this and my code I actually just contained empty functions and hooks

This is not the 1st time I got this, last time I recovered from my nightly backup and lost the accesslog, watchdog and some cache I am not backing up nightly

I think this is a critical issue, I'll do my best to investigate it anyway your tip saved me! 10x!

Paula (not verified)

Sat, 2008-05-03 13:32

Thanks so much for this. I had the same problem with Drupal 6.1 when uploading the Views Module. It just killed the site and I had no idea how to get it back up. I deleted the module and then followed your instructions and it brought the site back online. Thanks again!!!

Anonymous (not verified)

Wed, 2008-05-28 14:10

I was configuring Drupal 6 last night and was stopped dead in my tracks by this issue. I was this close to re-installing Drupal when I stumbled upon your blog post. THANK YOU!

Jim (not verified)

Sat, 2008-06-07 04:15

I also had this issue when installing the Views module, version 6.x-2.0-beta3.

Hopefully it gets fixed before it's out of beta!

-Jim

thanks a lot.

I have faced this problem on a live site also in latest 6.x stable versions of drupal. You can clear the all cache with drupal_flush_all_caches(); This will also rebuild the menu router table.

I added this to a separate file so that I can run it frequently while developing, also it helps on live sites where I dont have to install the devel module.

http://pshahmumbai.wordpress.com/2009/08/09/clear-drupal-caches/

javi (not verified)

Wed, 2010-03-10 16:09

It works like a charm! Thanks a lot!

If you have to keep caching disabled, then you have a serious problem indeed. Sure, if your menu breaks on all page hits and doesn't break with caching disabled, you can keep caching disabled while you fix the problem. But please do not consider disabling caching a production-level solution.

The workaround I suggest here, as well as your mention of disabling caching in settings/performance, is here to get your site running again so you can find the culprit and fix it: Drupal is designed to work with multiple levels of caching enabled, and is real slow without at least the builtin caching: one should neven run with caching disabled past the debugging stage.

For me all these flush-cash tricks in index.php did not work. I could also not log in.

Finally what I did is go to settings.php and set $update_free_access = TRUE; and then run the update.php script - this finally gave me back my menu_router data. (this was in a multi site environment so maybe the index.php trick was updating the wrong database? I dont know..)

Anonymous (not verified)

Mon, 2011-10-17 22:18

Great time saver!! :)

This happened to me working on a hook_menu_alter() function. My menu_router table only had 3 links (including node) in it.

Saurav (not verified)

Sun, 2012-11-04 03:04

Hello Sir,

I am getting 404 in all pages of my drupal installation and I am not able to perform any operation on my website (deleted: now a domain parking). Looking at your post I tried to locate the menu_rebuild() function in index.php file but its no present. My webhost is also not able to solve the problem. Please help me so that I can recover my website.

Thanks and regards,
Saurav