Is there a contrib module that can define access control based on the url path of content? So if an anonymous user goes to www.mysite.com/pages/test they can reach it, but if they go to www.mysite.com/hidden/stuff they can't get to it since it is in the /hidden/ path and they don't have an authenticated role.

I've already looked into controlling it based on content types, workbench groups, etc. Don't want to go with Workspaces since it is experimental and requires a whole other suite of modules to function.

Ideally, I'd like to be able to allow and block users with certain roles access to content that follows a specific path. Hoping there's something that already exists to handle this.

  • I don't know whether there is a module, but I wouldn't install a heavy weight module for this, either. You could easily solve this in a few lines of code in an early request subscriber, right after the authentication subscriber, the current user is the only information you need to make this decision. Then either set an unthemed 403 response (fast) or throw an access denied exception to get a themed 403 page (slower).
    – 4uk4
    Commented Sep 17, 2018 at 16:38
  • @4k4 I agree, don't want to add a heavyweight module. I will add the solution we came to below with an existing module.
    – Stan
    Commented Sep 18, 2018 at 14:38

1 Answer 1


What we ended up using was an existing module that we have already installed (Context) along with a custom block.

We created a new context for hidden sections of our site using the condition of the request path and the user role anonymous. From there our two reactions were to hide all sections within our theme except ones for help messages to our users, and to add a custom block to that help section.

Works like a charm and is fairly straightforward to change and keep track of in config.

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.