disable the default node page
GetLives - June 23, 2009 - 22:23
I have been asked to removed the /node page from a Drupal site, and I honestly don't know how. Would I disable the page within a theme, or disable it in some kind of admin option? This should be a simple task, but I can't find info about it anywhere.

Good question... I started
Good question... I started answering the way I'd think would work (provide a 301 redirect in .htaccess) but decided to test it first, and found that it redirected to ?q=node even though I pointed to the root of the domain (or if Global Redirect is installed, it instead causes an infinite loop). I then tried to write a bit of mod_rewrite based on the www/non-www rule, but I'm not too great at regular expressions yet so my attempt didn't succeed yet. I checked some big Drupal sites and it appears they too forget to deal with this appropriately (and since almost no major Drupal site uses the default front page, this leads to some pretty crazy looking broken pages on major Drupal sites at /node hehe). Of course this is usually denied in robots.txt so search engines are not adversely affected (and won't index the page), but it certainly would be nice to avoid that broken page. Hopefully someone will chime in with a good solution... if not I'll let you know if I figure it out or come across the information.
-- David
davidnewkerk.com | absolutecross.com
View my Drupal lessons & guides
One way to consider
Though it may be possible by other means as well, I found one way that appears to work, and it's not too hard to implement (follow my guide on starting your own very simple custom module).
Here's the code to add to the mini module:
/**
* Implementation of hook_menu().
*/
function MODULENAME_menu() {
$items = array();
// Disable the default /node front page.
$items['node'] = array (
'title' => 'node',
'page callback' => 'drupal_not_found',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
After you save this in the module, you need to clear the Menu cache (Site configuration > Performance should do the trick). This only disables the /node path, but not /node/#. For the rest I recommend Global Redirect module, which will redirect any node/# paths automatically to their alias paths.
-- David
davidnewkerk.com | absolutecross.com
View my Drupal lessons & guides
Hm. I tried adding an alias
Hm.
I tried adding an alias from /node to (eg) node/47.
I thought that may be a quick fix.
Wasn't.
.dan.
Use hook_menu_alter. Create a
Use hook_menu_alter. Create a module and you can "unset/disable" the page a menu has created.
<?phpfunction modulename_menu_alter(&$items) {
// Disable the page node
$items['node']['access callback'] = FALSE;
}
?>
Remember to clear the cache in performance after you created the module and installed it.
that failed in 6.x
at least in 6.14 which is what i'm running - the l() function in includes/common.inc fails because the $options parameter being passed in is NULL
i replaced $items['node'] with a call to my own function that does a redirect with drupal_goto('',null,null,301); - that *seems* to work so far.
i'd sure think there's a better way to do this, though.
ah, spoke too soon
that was actually a node_breadcrumb bug bollixing up the 403 page! your code works fine.