11

I have many basic pages where I need the user to be logged-in in order to view them. How do I customize the site access denied page?

7

A custom access denied page can be defined under /admin/config/system/site-information. For example, one common 404 error page is provided by the Search404 module.

All you have to do is define your own page, perhaps with a teaser from the requested page and informing the user that access to the full content requires that they be logged in.

This will probably require tha you put some php code into the page body, or you might use the Search404 module as the basis for developing your own module to handle this.

Edit: The more I think about this the more interesting the question becomes. I think a case might be made for a 'View Teaser' permission in addition to 'View published content'. In other words, the page could be available for all users, but the teaser would display instead of the full content, and a message could be displayed indicating that the user had to be logged in to view the full content, much like is done for comments now. Perhaps an idea for a contributed model (could not find one on D.O.).

7

I think you can use page--403.tpl.php and page--404.tpl.php and code in template.php via

function THEMENAME_preprocess_page(&$variables) {    
  $status = drupal_get_http_header("status");  
  if($status == '403 Forbidden') {
    $variables['theme_hook_suggestions'][] = 'page__403';
  }
  if($status == '404 Not Found') {
    $variables['theme_hook_suggestions'][] = 'page__404';
  }
}
  • Tested. It works. But remember that this hook is only run right after flushing cache. – Ignacio Segura Postigo Feb 7 '17 at 14:35
2

I am using the Custom error module for this.

To get redirect to originally requested page after a 403 to work, I've created this patch.

Here are two examples of my uses of the module:

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.