Assume the relative paths for your 3 URLs are like my/path1
(for ULR1
), my/path2
(for ULR2
) and my/path3
(for ULR3
). And assume your homepage has a relative path MyHomePage
. And assume this question is about D7.
With these assumptions, you could use a rule that answers your question which looks like so (in Rules export format):
{ "rules_limit_access_to_some_urls" : {
"LABEL" : "Limit access to some URLs",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules" ],
"ON" : { "init" : [] },
"IF" : [
{ "data_is" : {
"data" : [ "site:current-page:path" ],
"op" : "IN",
"value" : { "value" : [
"my\/path1",
"my\/path2",
"my\/path3"
]
}
}
}
],
"DO" : [
{ "redirect" : { "url" : "MyHomePage" } },
{ "drupal_message" : {
"message" : "Access to the content located at \u0022\u003Cstrong\u003E[site:current-page:path]\u003C\/strong\u003E\u0022 is not allowed.",
"type" : "warning"
}
}
]
}
}
Note site:current-page:path
token in this rule, which is different from site:current-page:url
.
To make the above rule work in similar situations, just adapt the paths by changing 'my/pathX' (with X=1, 2, 3) to whatever fits. And adapt the message to be shown.
Some more samples where you can see this technique at work:
Remark: Instead of using a data comparison in this Rules Condition, you may also want to try using a text comparison. That would allow you to use regular expressions. If your URLs have a common pattern for which you can write to single regular expression (such as URLx, with x=1, 2, 3, ..., 456, 457, ...), you would only need 1 such Rules Condition.
request_uri()
with this array (array_search()
orin_array()
will come in handy.