1

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.

2
  • 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
    Commented Jan 14, 2016 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
    Commented Jan 15, 2016 at 8:53

2 Answers 2

0

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.

3
  • 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
    Commented Jan 15, 2016 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 Commented Jan 15, 2016 at 9:01
  • 1
    You probably want the Global Redirect module.
    – Kevin
    Commented Jul 31, 2017 at 13:11
0

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 and acknowledge you have read our privacy policy.

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