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?
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityDrupal 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?
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
.
Create a path alias that redirects from /node to the page you want to use as front page.
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';
}
<?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 = '';
}
}
?>
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.
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
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.
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.
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
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
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.
/node
can still be reached, it just won't be visible by default
– Laxman13
Mar 21 '11 at 20:45
You can use the Rules module to check the url before viewing a page and redirect users to another page if you'd like.
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.
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']);
}
}
}