You are here

README.txt in Customerror 7

Same filename and directory in other branches
  1. 8 README.txt
  2. 5 README.txt
  3. 6 README.txt
CUSTOMERROR README.txt
======================


CONTENTS OF THIS FILE
---------------------

* Introduction
* Installation
* Configuration
  - Redirecting upon login
  - Custom redirects for 404 errors
* Submodule
* Integration with other modules
* FAQ
* Maintainers


INTRODUCTION
------------

This module allows the site admin to create custom error pages for
HTTP status codes 403 (access denied) and 404 (not found), without the
need to create nodes for each of them.

Main features:

* Configurable page title and descriptions.
* There are no author and date/time headers as with normal nodes.
* Any HTML formatted text can be be put in the page body.
* The error pages are themeable.
* Users who are not logged in and try to access an area that requires
  login will be redirected to the page they were trying to access after
  they login.
* Allows custom redirects for 404s.

Since the error pages are not real nodes, they do not have a specific
content type, and will not show up in node listings.

At present, the module can be set up to handle 403 and 404
errors. Drupal only allows those two errors to be assigned custom
pages. However, the design of the module is flexible and can
accommodate future error codes easily.

This module does not require any new database tables to be installed.


 * For a full description of the module, visit the project page:
   https://www.drupal.org/project/customerror
 * To submit bug reports and feature suggestions, or to track changes:
   https://www.drupal.org/project/issues/customerror
 * For more documentation, please see:
   https://www.drupal.org/node/2064843


INSTALLATION
------------

1. Install the CustomError module directory in the directory where you
   keep contributed modules (e.g. sites/all/modules/).

2. Go to the Modules page
   - Enable the CustomError module.
   Click on Save configuration.

3. Configure Error reporting
   - Go to Configuration -> System -> Site information
   - For 403 (access denied), enter the value:
       customerror/403
   - For 404 (not found), enter the value:
       customerror/404
   Click on Save configuration.

4. Configure the module:
   - Go to Configuration -> System -> Custom error
   - Enter any title and description you want for the 404 (not found)
     and 403 (access denied) pages.
   - You may also set theme to be used on the error pages. The first
     option (System default) lets the system set the theme. Each of
     the remaining options lets you set an explicit theme to be used
     on error pages (but it will not override the administration
     theme, if set).
   - You can use any HTML tags to format the text.
   Click on Save configuration.

5. Test your error pages.
   - Copy your present admin page url.
   - Try to go to a non-existent Drupal page on your site.
   You should see your custom error page for 404 (not found) page.

   - Log out from your site.
   - Paste the admin page url and try to go there.
   You should see your custom error page for 403 (access denied) page.


CONFIGURATION
-------------

Custom redirects for 404 errors
-------------------------------

It is possible to set up custom redirects for status code 404 (not
found).

For example if you had a page called foo and a page called xyz, then
you moved them to a page called bar, and abc respectively, you can
setup a redirect pair of:

  ^foo$ bar
  ^xyz$ abc

The first pair will transparently redirect users trying to access
example.com/foo to example.com/bar.  The second pair will
transparently redirect users trying to access example.com/xyz to
example.com/abc.

You can have multiple pairs of redirects. Each must be on a line by
itself.

Note that the first argument is a regexp, and the second argument is a
path. You have to use one space between them, and enter each pattern
on a line by itself. You cannot use variables.

For more flexible URL redirection or rewriting, including variables,
you may consider the Drupal Redirect module, or using an external URL
rewrite engine, such as Apache mod_rewrite.  If you use some other
means of redirection or rewriting, you should refrain from using the
redirect feature of CustomError.



Using custom PHP on an error page
----------------------------------

If you want error pages to contain PHP, enable the core PHP filter
module.  This allows you to include PHP code (enclosed in <?php ?>
tags) for the error page message.  Note that this can be dangerous in
some situations. Make sure that you are aware of the implications.

Here is an example of how to add custom PHP to a 403 error page to
check if the user is logged in.  If the user is not logged in, a
message saying 'access denied: insufficient permissions' is shown,
otherwise the user is given the option to log in:

<?php
if (user_is_logged_in()) {
   $output = '<p>' . t('access denied: insufficient permissions') . '</p>';
} 
else {
  $output = t('If your user account has access to this page, please !message.',
    array(
      '!message' => l(t('log in'), 'user'),
    )
  );
  $output .= '</p>';
}
print $output;
?>

Note that enabling the PHP filter module is depreciated (it will no
longer be part of core for Drupal 8).  For a safer method to show
different error pages for access denied pages for anonymous and logged
in users, enable the submodule that is part of the project:
CustomError alternate for authenticated.

If your handling of access denied errors allows the user to log in
after been shown the message, CustomError keeps track of what page the
user is trying to access. After succesfully logging in, the user will
be redirected to the page he or she originally requested.


SUBMODULE
---------

Packaged with the project is the submodule: CustomError alternate for
authenticated.

Enabling this sub-module will add fields that allow the administrator
to add a title and description for 403 (access denied) for
authenticated users that are different from status code 403 (access
denied) for anonymous users.

See the submodule's own README.md for more documentation.


INTEGRATION WITH OTHER MODULES
------------------------------

The function customerror_page() can be called by other modules to have
CustomError or CustomError alternate for authenticated handle the
error.

* LoginToboggan[1]:
  If this module is enabled, in can enhance CustomError's handling of
  access-denied messages, but you have to be careful to set them up to
  work together correctly.

  These two modules both attempt to take over handling of system 403
  ("access denied") messages, and can conflict. CustomError does it by
  asking you to go to "admin/config/system/site-information" and
  manually setting the "Default 403 (access denied) page" to
  "customerror/403", whereas LoginToboggan sets that same field to
  "toboggan/denied" automatically (overwriting any other value that
  was there), when you enable its "Present login form on access denied
  (403)".

  If you are using CustomError with LoginToboggan, you should allow
  LoginToboggan to perform this take-over (in other words, don't set
  the "Default 403 (access denied) page" to "customerror/403"). This
  way, if someone attempts to access a page that they don't have
  access to, LoginToboggan will first give them a chance to log in if
  they haven't yet. If they still don't have access to the page,
  CustomError then takes over from LoginToboggan (by overriding one of
  its theme functions), displaying its customisable messages for
  access-denied errors.


FAQ
---

Q: I want to prevent robots from indexing my custom error pages by
   setting the robots meta tag in the HTML head to NOINDEX.
A: There is no need to. CustomError returns the correct HTTP status
   codes (403 and 404). This will prevent robots from indexing the
   error pages.
	
Q: I want to customize the custom error template output.
A: In your site's theme, duplicate your page.tpl.php to be
   page--customerror.tpl.php and then make your modifications there.

Q: I want to have a different template for my 404 and 403 pages.
A: Duplicate your page.tpl.php page to be
   page--customerror--404.tpl.php and
   page--customerror--403.tpl.php. You do not need a
   page--customerror.tpl.php for this to work.

Q: Some 403 errors (e.g. "http://example.org/includes") are served by
   the Apache web server and not by CustomError. Isn't that a bug?
A: No. CustomError is only designed to provide a custom error page
   when the page is processed by Drupal.  The .htaccess file that
   comes with Drupal will catch some attempts to access forbidden
   directories before Drupal even see the requests.  These access
   attempts will get the default Apache 403 error document, unless you
   use the Apache ErrorDocument directive to override this, e.g:
   ErrorDocument 403 /error/403.html For more information about this,
   see: http://httpd.apache.org/docs/current/custom-error.html


MAINTAINERS
-----------

Principal author is Khalid Baheyeldin
(http://baheyeldin.com/khalid and http://2bits.com).

Port to Drupal 7 port has been overseen by Gisle Hannemyr
(https://www.drupal.org/u/gisle).

The authors can be contacted for paid customizations of this module
as well as Drupal consulting, installation, development, and
customizations.


[1]: https://www.drupal.org/project/logintoboggan

File

README.txt
View source
  1. CUSTOMERROR README.txt
  2. ======================
  3. CONTENTS OF THIS FILE
  4. ---------------------
  5. * Introduction
  6. * Installation
  7. * Configuration
  8. - Redirecting upon login
  9. - Custom redirects for 404 errors
  10. * Submodule
  11. * Integration with other modules
  12. * FAQ
  13. * Maintainers
  14. INTRODUCTION
  15. ------------
  16. This module allows the site admin to create custom error pages for
  17. HTTP status codes 403 (access denied) and 404 (not found), without the
  18. need to create nodes for each of them.
  19. Main features:
  20. * Configurable page title and descriptions.
  21. * There are no author and date/time headers as with normal nodes.
  22. * Any HTML formatted text can be be put in the page body.
  23. * The error pages are themeable.
  24. * Users who are not logged in and try to access an area that requires
  25. login will be redirected to the page they were trying to access after
  26. they login.
  27. * Allows custom redirects for 404s.
  28. Since the error pages are not real nodes, they do not have a specific
  29. content type, and will not show up in node listings.
  30. At present, the module can be set up to handle 403 and 404
  31. errors. Drupal only allows those two errors to be assigned custom
  32. pages. However, the design of the module is flexible and can
  33. accommodate future error codes easily.
  34. This module does not require any new database tables to be installed.
  35. * For a full description of the module, visit the project page:
  36. https://www.drupal.org/project/customerror
  37. * To submit bug reports and feature suggestions, or to track changes:
  38. https://www.drupal.org/project/issues/customerror
  39. * For more documentation, please see:
  40. https://www.drupal.org/node/2064843
  41. INSTALLATION
  42. ------------
  43. 1. Install the CustomError module directory in the directory where you
  44. keep contributed modules (e.g. sites/all/modules/).
  45. 2. Go to the Modules page
  46. - Enable the CustomError module.
  47. Click on Save configuration.
  48. 3. Configure Error reporting
  49. - Go to Configuration -> System -> Site information
  50. - For 403 (access denied), enter the value:
  51. customerror/403
  52. - For 404 (not found), enter the value:
  53. customerror/404
  54. Click on Save configuration.
  55. 4. Configure the module:
  56. - Go to Configuration -> System -> Custom error
  57. - Enter any title and description you want for the 404 (not found)
  58. and 403 (access denied) pages.
  59. - You may also set theme to be used on the error pages. The first
  60. option (System default) lets the system set the theme. Each of
  61. the remaining options lets you set an explicit theme to be used
  62. on error pages (but it will not override the administration
  63. theme, if set).
  64. - You can use any HTML tags to format the text.
  65. Click on Save configuration.
  66. 5. Test your error pages.
  67. - Copy your present admin page url.
  68. - Try to go to a non-existent Drupal page on your site.
  69. You should see your custom error page for 404 (not found) page.
  70. - Log out from your site.
  71. - Paste the admin page url and try to go there.
  72. You should see your custom error page for 403 (access denied) page.
  73. CONFIGURATION
  74. -------------
  75. Custom redirects for 404 errors
  76. -------------------------------
  77. It is possible to set up custom redirects for status code 404 (not
  78. found).
  79. For example if you had a page called foo and a page called xyz, then
  80. you moved them to a page called bar, and abc respectively, you can
  81. setup a redirect pair of:
  82. ^foo$ bar
  83. ^xyz$ abc
  84. The first pair will transparently redirect users trying to access
  85. example.com/foo to example.com/bar. The second pair will
  86. transparently redirect users trying to access example.com/xyz to
  87. example.com/abc.
  88. You can have multiple pairs of redirects. Each must be on a line by
  89. itself.
  90. Note that the first argument is a regexp, and the second argument is a
  91. path. You have to use one space between them, and enter each pattern
  92. on a line by itself. You cannot use variables.
  93. For more flexible URL redirection or rewriting, including variables,
  94. you may consider the Drupal Redirect module, or using an external URL
  95. rewrite engine, such as Apache mod_rewrite. If you use some other
  96. means of redirection or rewriting, you should refrain from using the
  97. redirect feature of CustomError.
  98. Using custom PHP on an error page
  99. ----------------------------------
  100. If you want error pages to contain PHP, enable the core PHP filter
  101. module. This allows you to include PHP code (enclosed in
  102. tags) for the error page message. Note that this can be dangerous in
  103. some situations. Make sure that you are aware of the implications.
  104. Here is an example of how to add custom PHP to a 403 error page to
  105. check if the user is logged in. If the user is not logged in, a
  106. message saying 'access denied: insufficient permissions' is shown,
  107. otherwise the user is given the option to log in:
  108. if (user_is_logged_in()) {
  109. $output = '

    ' . t('access denied: insufficient permissions') . '

    ';
  110. }
  111. else {
  112. $output = t('If your user account has access to this page, please !message.',
  113. array(
  114. '!message' => l(t('log in'), 'user'),
  115. )
  116. );
  117. $output .= '

    ';
  118. }
  119. print $output;
  120. ?>
  121. Note that enabling the PHP filter module is depreciated (it will no
  122. longer be part of core for Drupal 8). For a safer method to show
  123. different error pages for access denied pages for anonymous and logged
  124. in users, enable the submodule that is part of the project:
  125. CustomError alternate for authenticated.
  126. If your handling of access denied errors allows the user to log in
  127. after been shown the message, CustomError keeps track of what page the
  128. user is trying to access. After succesfully logging in, the user will
  129. be redirected to the page he or she originally requested.
  130. SUBMODULE
  131. ---------
  132. Packaged with the project is the submodule: CustomError alternate for
  133. authenticated.
  134. Enabling this sub-module will add fields that allow the administrator
  135. to add a title and description for 403 (access denied) for
  136. authenticated users that are different from status code 403 (access
  137. denied) for anonymous users.
  138. See the submodule's own README.md for more documentation.
  139. INTEGRATION WITH OTHER MODULES
  140. ------------------------------
  141. The function customerror_page() can be called by other modules to have
  142. CustomError or CustomError alternate for authenticated handle the
  143. error.
  144. * LoginToboggan[1]:
  145. If this module is enabled, in can enhance CustomError's handling of
  146. access-denied messages, but you have to be careful to set them up to
  147. work together correctly.
  148. These two modules both attempt to take over handling of system 403
  149. ("access denied") messages, and can conflict. CustomError does it by
  150. asking you to go to "admin/config/system/site-information" and
  151. manually setting the "Default 403 (access denied) page" to
  152. "customerror/403", whereas LoginToboggan sets that same field to
  153. "toboggan/denied" automatically (overwriting any other value that
  154. was there), when you enable its "Present login form on access denied
  155. (403)".
  156. If you are using CustomError with LoginToboggan, you should allow
  157. LoginToboggan to perform this take-over (in other words, don't set
  158. the "Default 403 (access denied) page" to "customerror/403"). This
  159. way, if someone attempts to access a page that they don't have
  160. access to, LoginToboggan will first give them a chance to log in if
  161. they haven't yet. If they still don't have access to the page,
  162. CustomError then takes over from LoginToboggan (by overriding one of
  163. its theme functions), displaying its customisable messages for
  164. access-denied errors.
  165. FAQ
  166. ---
  167. Q: I want to prevent robots from indexing my custom error pages by
  168. setting the robots meta tag in the HTML head to NOINDEX.
  169. A: There is no need to. CustomError returns the correct HTTP status
  170. codes (403 and 404). This will prevent robots from indexing the
  171. error pages.
  172. Q: I want to customize the custom error template output.
  173. A: In your site's theme, duplicate your page.tpl.php to be
  174. page--customerror.tpl.php and then make your modifications there.
  175. Q: I want to have a different template for my 404 and 403 pages.
  176. A: Duplicate your page.tpl.php page to be
  177. page--customerror--404.tpl.php and
  178. page--customerror--403.tpl.php. You do not need a
  179. page--customerror.tpl.php for this to work.
  180. Q: Some 403 errors (e.g. "http://example.org/includes") are served by
  181. the Apache web server and not by CustomError. Isn't that a bug?
  182. A: No. CustomError is only designed to provide a custom error page
  183. when the page is processed by Drupal. The .htaccess file that
  184. comes with Drupal will catch some attempts to access forbidden
  185. directories before Drupal even see the requests. These access
  186. attempts will get the default Apache 403 error document, unless you
  187. use the Apache ErrorDocument directive to override this, e.g:
  188. ErrorDocument 403 /error/403.html For more information about this,
  189. see: http://httpd.apache.org/docs/current/custom-error.html
  190. MAINTAINERS
  191. -----------
  192. Principal author is Khalid Baheyeldin
  193. (http://baheyeldin.com/khalid and http://2bits.com).
  194. Port to Drupal 7 port has been overseen by Gisle Hannemyr
  195. (https://www.drupal.org/u/gisle).
  196. The authors can be contacted for paid customizations of this module
  197. as well as Drupal consulting, installation, development, and
  198. customizations.
  199. [1]: https://www.drupal.org/project/logintoboggan