How to specify a Rules event like "Content is 'going to be' viewed"? To answer the question about "How to restrict access to a node via node/12 and allow access via a path like content/sometitle?", I thought it should be possible to use the Rules module to do so.

I was thinking about a rule as in this exported rule (which has "Content is viewed" as event):

{ "rules_disallow_using_urls_like_node_123" : {
    "LABEL" : "Disallow using URLs like node\/123",
    "PLUGIN" : "reaction rule",
    "ACTIVE" : false,
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_view" : [] },
    "IF" : [
      { "data_is" : { "data" : [ "site:current-page:path" ], "value" : "node\/[node:nid]" } }
    ],
    "DO" : [
      { "redirect" : { "url" : "no_access" } },
      { "drupal_message" : { "message" : "Sorry, URLs like node\/[node:nid] are not allowed around here ..." } }
    ]
  }
}


Here is the challenge (and my actual question): for any node you visit, and even when visiting nodes using the path of such nodes, the rules action always gets executed. That makes me wonder how I can rework that "Content is viewed" event into something like "Content is 'going to be' viewed", so before Drupal is actually going to display the requested node? And this without writing a custom module.

To better explain the 'going to be'-part of it: compare it to the Content Access" module: if you try to visit a page for which content access is set so that you do NOT have permission to (e.g.) view it, then Drupal will FIRST check via content access if you do have access to it, then decides you have no permission, and then you will NOT actually be able to "view" that page (even though you asked for it). So that "will FIRST check" is similar to "going to be" ...

I also looked at the (unasnwered) question about "I cannot see the Rules event &quot;Page is going to be viewed&quot;", in which one of its comments points to issue nr 514824 (which is for D6). And in that issue there is Fago's comment #8 like so:


  Use the "Content is being viewed" event when you need the node.


Assuming that was available (and working as such) in D6, what is the D7 equivalent of this event, if any? Because, obviously, my sample above seems to indicate that in D7 it doesn't work like that anymore.

Note: The exported source above is intentionally DISABLED, because if you'd want to import it and enable it, then it is always going to get triggered for ANY node you view. Only URLs starting with (eg) /user or /admin will not satisfy the Event in this rule (so that at least you can disable this rule again to be able to view /node paths also again).
You should react to the System > Drupal is initializing event and check for the URL there:

{ "rules_check_url" : {
    "LABEL" : "Disallow node/* access",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "init" : [] },
    "IF" : [
      { "text_matches" : {
          "text" : [ "site:current-page:url" ],
          "match" : "node\/\\d+$",
          "operation" : "regex"
        }
      }
    ],
    "DO" : [
      { "drupal_message" : {
          "message" : "Sorry, URLs like [site:current-page:url] are not allowed around here ...",
          "type" : "error"
        }
      },
      { "redirect" : { "url" : "no_access" } }
    ]
  }
}


Also, notice that in the rule above we test against the site:current-page:url token, which contains the (full) original URL (as seen in the browser address bar). Checking against site:current-page:path would not work in this case as all nodes, even the ones being accessed via URL alias, would match.