0

Is there a path with which I can call the "Access denied" page?

I'm trying to implement a rule that redirects to such a page because I want to prevent users and search robots from visiting certain nodes.

This is for Drupal 6.

2
  • 3
    @Mohammad Ali Akbari's answer is the thing to do if you really do need to use a rule. If you simply need to hide some nodes from being viewed on their own, then take a look at the Rabbit Hole module.
    – mpdonadio
    Commented May 2, 2012 at 20:23
  • @MPD Thank you, I'll go with Rabbit Hole. If you post your comment as an answer I can tick it as the correct one.
    – user6966
    Commented May 3, 2012 at 15:42

3 Answers 3

3

If you simply need to add some logic to prevent nodes from being viewed on their own, there are a few well-known solutions. If you search here, you will find the various options.

After trying a few different methods, using the Rabbit Hole module is my new preferred solution. One, you don't need to roll your own solution in a custom module anymore. Two, the configuration is rather flexible and supports multiple behaviors within a single site. I don't see myself going back the method I used to promote.

6

You don't need to redirect to any page; you can produce the access denied page by calling drupal_access_denied().

6
  • 5
    Correct. You never want to redirect away from the URL that gets denied. The URL itself should generate the 403. When you redirect, a 301 would get generated for the URL and then a 403 for the page you redirected to. Same goes for making a URL 404.
    – mpdonadio
    Commented May 2, 2012 at 19:36
  • I see that generating a 403 error is better. But is it possible to call this function with my rule?
    – user6966
    Commented May 2, 2012 at 20:08
  • 1
    You can have an action on a rule to call custom PHP.
    – mpdonadio
    Commented May 2, 2012 at 20:22
  • 1
    Unfortunately when calling drupal_access_denied(); the "Access denied" page gets displayed in addition to the normal node view.
    – user6966
    Commented May 3, 2012 at 15:22
  • 2
    @BernhardV, try it as adding drupal_access_denied(); exit;
    – mpdonadio
    Commented May 3, 2012 at 17:16
0

You can create your own action in hook_rules_action_info() Here is sample what you can do in your_module.rules.inc file.

/**
 * @file your_module.rules.inc
 * Contains custom code for Rules module.
 */
/**
 * Implements hook_rules_action_info().
 */
function your_module_rules_action_info() {
  return array(
    '_your_module_access_denied' => array(
      'label' => t('Access Denied'),
      'group' => t('Nodeex Rules'),
    ),
  );
}
/**
 * Rule action _your_module_access_denied.
 */
function _your_module_access_denied() {
  return drupal_access_denied();
}
1
  • Also, the content_access module offers optional rules integration if you want to avoid adding custom code.
    – danbohea
    Commented Jul 4, 2016 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.