22

Drupal out of the box comes with a page (which is the default homepage) that is assigned to the node path.

How do I avoid users reach it, and redirect them to the actual homepage of the site?

1
  • I've used the solution proposed by @kiamlaluno to redirect the node to a different path. – user704 Mar 22 '11 at 23:39

14 Answers 14

17

There is no easy way to hide that page. If you don't use it, you can implement hook_menu_alter(), and either remove it completely, or set its access callback to FALSE.

1
9

Create a path alias that redirects from /node to the page you want to use as front page.

3
  • 1
    This does not work for me with url alias module, aliasing /node to <front> or index.php. I m trying to forward to just / – john Dec 4 '11 at 1:00
  • 5
    Odd I did /node to <front> and it work fine. – Sean Bannister Jun 12 '12 at 14:51
  • Like you @john the UI of the aliasing does not allow me to set forward to the front page. I had to use the redirect module instead. – Postscripter Sep 25 '16 at 11:36
6

I prefer to alter the page callback of /node so it shows an error 404 Page.
This always shows your custom 404 page when accessing /node.

function yourmodule_menu_alter(&$items) {
    $items['node']['page callback'] = 'drupal_not_found';      
}
0
4
<?php
function MY_MODULE_menu_alter(&$callbacks) {
unset($callbacks['node']);
}
?>

or add this to settings.php (URL inbound stuff)

<?php
function custom_url_rewrite_inbound(&$result, $path, $path_language) {
  if ($path == 'node') {
    $result = ''; 
  }
}
?>
2

I used the Redirect module: I just added a new 301 redirect from node to <front>.

1

Similar to berdirs answer, I have the following code included in a module that is part of a custom distro we build from:

function HOOK_menu_alter(&$items) {
  $items['node']['page callback'] = '_HOOK_empty_home';
}

function _HOOK_empty_home() {
  drupal_set_title('');
  return '';
}

That way I can keep the 'node' path as the frontpage and use context to position blocks to build the required frontpage.

1

You can create a page mapped to /node which is not published. So the users who will call this path will have an access forbidden page

1

The easy solution for me was to create a page that I wanted to be the home page and set the URL to /node. Then under /admin/config/system/site-information set the default front page to /node. You never see "/node" in URL unless someone actually types it in. It's quick, easy and clean, provided you want to set your homepage URL to /node.

1

You can create a new page with node URL and people can see a message redirecting them to visit the front page or choose a category of something.

1

I tried multiple things. Then for Drupal 7 and 8, I found this to be most easy, without writing any code:

download and enable node_page_disable, globalredirect and redirect modules.

(Note: node_page_disable module redirects /node to 404 not found error page.)

then add a redirect for /node --> front page

Please note that the redirect redirects both /node and /node/ to front page.

and a useful article to read: https://www.drupalaid.com/blog/3-things-you-should-hide

1
  • It's a view in D8, so drush @example.com views-disable frontpage will turn it off. Will still get a 404 though until the other things are done. – colan Jul 17 '17 at 20:26
0

Create a node, then go to site configuration -> site information, and set the home page to the path of the node. So if it's your first node, it would be node/1.

Edit: By default, just by creating a node that page will disappear if you check 'promote to front page'. The site information step will make that node your actual front page.

4
  • 1
    True, but /node can still be reached, it just won't be visible by default – Laxman13 Mar 21 '11 at 20:45
  • I misread what he was asking for. What about the Path redirect http://drupal.org/project/path_redirect module? – Mike L. Mar 21 '11 at 21:15
  • 1
    Unfortunately Path Redirect does not allow you to redirect from existing paths. It checks to see if the path you are trying to redirect from is a valid path and if so, the redirect is not created and a warning is displayed. – Laxman13 Mar 21 '11 at 21:36
  • Cool. I haven't used it in awhile, so wasn't positive. Thanks! – Mike L. Mar 21 '11 at 23:58
0

You can use the Rules module to check the url before viewing a page and redirect users to another page if you'd like.

  • Add rule with event: Content is going to be viewed
  • Add condition: Execute custom PHP code and check the path
  • Add action: Page Redirect and choose the path you want to redirect to
3
  • This does not only introduce severe performance penalties, it should be considered very unsafe. "Execute custom PHP" should not ever be suggested unless all the side-effects and downsides are very well known. -1 for that. – berkes Apr 19 '11 at 10:39
  • @berkes I would assume it is because Rules will perform a check on every page load and therefore slowing the site down? Why is it that "Execute custom php" is always frowned upon? Obviously not good for end user use, but are there downsides for developer use as well? Sorry if long, been working real hard to be the best I can with Drupal and learning the "ins and outs". (Could add second part as own question if needed) – Laxman13 Apr 19 '11 at 14:15
  • please consider a new Q "What are the downsides of using 'custom' PHP" with some example areas (blocks, views arguments, php-filter etc) where this can be discussed? – berkes Apr 19 '11 at 15:28
0

Popular question from quite some years ago, with quite some interesting answers already. However, guess what: "These days there's a module for it ... actually even two!" (not mentioned in any of the prior answers).

Read on for more details ... (quotes are from their project pages) ...

Node page admin (either D6 or D7):

This module adds an administration settings panel to handle /node page access. Once it is activated there are three posible configurations:

  • Core - Drupal core will handle node page access as usual: all users with 'access content' permission
  • Disabled - Nobody will be able to access /node. It will return 'Page not found' (404).
  • By permission - Access will be handled by a new permission: 'access node page'

Node Page Disable (either D6 or D7, though only rc2 versions):

Allows easy UI access and disabling of the path /node when not used. This was inspired by a security consideration in the Production Check Module.

-1

the best way is to hide nodes from template_preprocess_page function

function template_preprocess_page(&$variables) {
    if ($variables['is_front'] == 1) {
        if (isset($variables['page']['content']['system_main'])) {
            unset($variables['page']['content']['system_main']);
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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