This project is not covered by Drupal’s security advisory policy.

This module can provide a custom 403, 404, 401 contents based on the path.

Once you enable the module, you can head over to /admin/structure/custom4xx_config_entity to get started.

Click "Add a custom 4xx page" to create a new configuration. The options are pretty straightforward. The label is purely for human readability and organization. The 4xx Type is up to you. The Path to Apply To is what will produce the page, and the Path To Custom 403 Page is where the node or other entity that contains our content we want to show the user when they hit this 4xx. You can use "*" as a wildcard for defining the paths.

So, let's say we have created an article node, and in the body, we put something like:

"Sorry, you're not authorized to visit this page! Click here for more membership information!" 

We also setup the path to this article as "/membership/403-page". Now we're ready to create our custom 4xx entity to wire this page up as the 403 - Access Denied page contents.

For this example, let's say that if any unauthorized users visit our content we have created at "/members/foo" and "/members/bar", we want them to see the contents of this article so that they can be shown the instructional content from the article node.

So, all we have to do for this is to navigate to /admin/structure/custom4xx_config_entity/add. We can put the label as "Members 403 Page", set the type as 403, set our Path To Apply To as "/members/*", so that it will cover all URL's that are aliased with the /members, and we set the Path To Custom 403 Page as /members/403-page. That's it! Make sure to hit Save, and you should now see the entity listed in /admin/structure/custom4xx_config_entity. 

Now, assuming that /members/foo and /members/bar are both setup to only be available to certain roles or permissions, any anonymous or unauthorized users will be presented with the contents of /members/403-page when they visit the page.

A few notes / recap

The "Path To Custom 403 Page" will attempt to use the Entity API to render whatever it can find at that path. Node Content Type entities should definitely work. Custom entities should also work, assuming you've built them with a render / view mode.
As of right now, there's no real weighting involved, so the custom 4xx are evaluated by first come first serve. That means, if I created another custom 4xx for /members/foo, the wildcard one we used above would most likely apply first.

Supporting organizations: 

Project information

Releases