How do I change the redirect page for unpublished nodes? It seems that the standard Drupal behaviour for unpublished nodes is this: If a visitor types in a URL to an unpublished node they are redirected to a login page. To -me- that signals that the content is 'there' but they just need credentials.

So: Is there a way to change this behaviour so that if they type in a URL to an unpublished node, literally -nothing- happens? Or perhaps they are redirected to the home page?

Below is my attempt to redirect to home page. The page still redirects to the Access Denied. What I don't get is that if I alter the Rule so that it tests for role 'Administrator' it works -fine-. So apparently an Anonymous user has some special property?

{ "rules_redirect_unpubished_content_url_to_home_page" : {
    "LABEL" : "Redirect Unpubished Content URL To Home Page",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_view--bags_cases" : { "bundle" : "bags_cases" } },
    "IF" : [
      { "NOT node_is_published" : { "node" : [ "node" ] } },
      { "user_has_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "1" : "1" } }
        }
      }
    ],
    "DO" : [ { "redirect" : { "url" : "/" } } ]
  }
}

I also tried this:


function jch_utilities_node_view($node, $view_mode, $langcode) {
  if ($node->status != 1) {
        drupal_goto('/some-page');
  }
}

...and again, the 403 fires before this has a chance to run

Finally, I tried hook_init, but yet again, the 403 fires before this has a chance to run.

What am I missing?
The default behaviour is an "Access denied" page, because a visitor hasn't access to unpublished nodes.
It's not possible "nothing appens".
You could use Rules and create a Rule like this:


event: viewing a node
condition: user has role "anonymous"
condtion: node is unpublished
action: redirect to a custom page