# Use Rules with 'Drupal is initializing'

Use the [Rules][1] module to get this to work, you should be able to use the "Drupal is initializing" event. That will ensure that the rule gets triggered BEFORE the actual content of your "link with view" is shown.

# Use a 'Regular Expression'

That link that you want to "intercept", should be formatted in some type of regular expression, which you then use as your rules "Condition". so that you have a rule that corresponds to "before showing the actual content of something that matches a specific path ...". After you get that part to work, your Rules "action" should specify the actual redirect to be performed..

# Sample rule

Refer to the "option 1" part of my answer to the question about "http://drupal.stackexchange.com/questions/165114/how-to-restrict-access-to-a-node-via-node-12-and-allow-access-via-a-path-like-co/165126#165126", which contains this rule in export format:

    { "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" } }
        ]
      }
    }

Here are some suggested tuning of the above sample to make it work for your case also:

- machine name and label.
- replace the `node/*` by your path (in the "label", and the regular expression).
- replace the path in the action part of the rule by your target path (more details below), and check if you do want some type of error message to be shown (if not remove that part of the action).

# Use the value of the [name] variable in the redirect

To make the value of the URL argument available as new variable to Rules, you can use the [Rules URL Argument][2] module. Here is a quote about it (from its project page):

> ... provides two rules conditions based on URL arguments:

> - check if a URL argument is present.
> - compare the value of an URL argument.

> It also provides an action that makes the value of an URL argument available as new variable to Rules.

The newly provided Rules actions and conditions can be found under the "URL Argument" conditions and actions groups in the rule configuration interface.

Refer to [Comment # 3 in issue # 1686360][3] for an example that illustrates how to use it.

  [1]: https://www.drupal.org/project/rules
  [2]: https://www.drupal.org/project/rules_url_argument
  [3]: https://www.drupal.org/node/1686360#comment-6306112