I have the module Path auto installed. I would like that the user could not access the content by the URL http://www.myexample.com/node/7 and instead would have to follow the menu and other webpage links with its alias. So if I forgot to set an alias for a content, I will be redirected to 404 or home page. The goal is to protect the "real" URLs which Drupal generates when creating content via admin and modules.

  • You would like users to get 404, or be redirected to content under address you approve? Because 404 might be bit hard, and users may lose links, bookmarks they already created.
    – Mołot
    Jan 14 '16 at 17:41
  • You are right, it would be better to be redirected to the homepage or other address, but never the "real" address, i.e., if I have content in node = 295, I don't want the user to know that. She would always had to access via the frienly url.
    – Cesar
    Jan 15 '16 at 8:53

If you set the patterns for a content type on URL aliases. You get the "Generate automatic URL alias" So you never get the node/* urls on that content type.

You find the URL aliases section on your configuration page. Patterns is a tab there.

  • I must have something wrong in the config, because I have the pattern, the URLs are generated automatically, all works perfectly... but still, I can access /node/**node_id**. I can access being an admin and also a non-registered user.
    – Cesar
    Jan 15 '16 at 8:52
  • Sorry, I see what you mean now you have the good urls but when you type the node/* you get the page ash well. i found this when i googled it maybe it helps. drupal.org/node/500296 Jan 15 '16 at 9:01
  • 1
    You probably want the Global Redirect module.
    – Kevin
    Jul 31 '17 at 13:11

Using the Rules module you can implement a rule that looks similar to this:

{ "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" : "your_home_page" } }

To experiment with this rule in your own site, just copy the entire Rules code above, and paste it in a new Rule in your own site, created via the "Import" function. Then further edit/refine to make it fit in your own environment (e.g the "Sorry, ..." message to be shown, and/or the your_home_page path in the sample rule here).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.