You are here

README.txt in Context Redirect 7

Same filename and directory in other branches
  1. 6 README.txt
Context Redirect provides a "Reaction" for the Context module which redirects to
a configurable internal or external url when the context conditions are met.
The type of redirect issued (301, 302, 303 or 307) can be configured through the
context UI.

The module is very lightweight and is little more than a wrapper around the core
drupal_goto() function for the Context API.

## Comparison with other Drupal modules ##

Context cannot be used to register new paths within Drupal; it can only react to
conditions that have been met for the current user visiting a path that already
exists. If you just want to redirect from a new path to another you could
register the path with Drupal using some method outside of the Context API and
then use Context to perform the redirect but it is (usually) much more elegant
to simply register the path as a redirect in the first place.

If you're not comfortable writing custom code or the hook system (specifically
hook_menu) then check out the Page Manager Redirect module which can handle this
for you, alternatively Panels can achieve the same thing.

If you want to perform redirects for existing paths based on more complicated
conditions than just the current url then, in general, those page callback based
modules won't be flexible enough.

Without writing custom code, using robust and popular contrib modules you're
left with only Rules and/or Context. For the sake of triggering redirects
both modules will work almost identically under the hood so use whichever suits
your current needs best.

## Caveats ##

If your site is only using Drupal core caching, configured entirely through
the Performance configuration screen you can skip this section.

Context is fundamentally a PHP framework for checking existing conditions and
reacting to them. It does this though Drupal's system of "hooks" that have
always provided this functionality for developers writing their own code, but
with a nice point-and-click interface to make it accessible to a wider audience.
In this way Context is very similar to the Rules module.

Because Context is built on hooks it is a flexible and powerful way to manage
redirects. It allows the site builder to react to more subtle conditions
than just a path. For example, a user visiting the home page with a specific
role can be detected and redirected easily.

Unfortunately, redirects triggered by hooks are in danger of being bypassed
completely when Drupal and/or the server environment is configured so that hooks
are not triggered if the current page is cached. This is not the default
configuration of Drupal, you need very specific skills and knowledge to create
this problem for yourself - you should know who you are :P.

Redirects from this module will fail if ALL of the following conditions are met:

- The condition that triggers the redirect will be met by some anonymous users
  but not other.
- The current Drupal site has "fast cache" page caching or equivalent enabled.
  The most common ways of achieving this are:
  => Using the Boost module
  => Manually setting the 'page_cache_invoke_hooks' variable to FALSE in
     settings.php and enabling page caching
  => Installing a server based html cache like Varnish that can bypass Drupal
     completely.
  => Using "Aggressive" page caching in Drupal 6
- The current page is cached
- The cached version of this page is not a redirect, or redirects to the wrong
  url.

A practical example that meets all of these conditions would be a site with
Boost enabled that is attempting to redirect only those anonymous users that
view the site with mobile devices.

Generally though, if all of these conditions are met and you're expecting a PHP
based redirect to work reliably you probably need to rethink your site
architecture and use a server config or client (javascript) based redirection.

File

README.txt
View source
  1. Context Redirect provides a "Reaction" for the Context module which redirects to
  2. a configurable internal or external url when the context conditions are met.
  3. The type of redirect issued (301, 302, 303 or 307) can be configured through the
  4. context UI.
  5. The module is very lightweight and is little more than a wrapper around the core
  6. drupal_goto() function for the Context API.
  7. ## Comparison with other Drupal modules ##
  8. Context cannot be used to register new paths within Drupal; it can only react to
  9. conditions that have been met for the current user visiting a path that already
  10. exists. If you just want to redirect from a new path to another you could
  11. register the path with Drupal using some method outside of the Context API and
  12. then use Context to perform the redirect but it is (usually) much more elegant
  13. to simply register the path as a redirect in the first place.
  14. If you're not comfortable writing custom code or the hook system (specifically
  15. hook_menu) then check out the Page Manager Redirect module which can handle this
  16. for you, alternatively Panels can achieve the same thing.
  17. If you want to perform redirects for existing paths based on more complicated
  18. conditions than just the current url then, in general, those page callback based
  19. modules won't be flexible enough.
  20. Without writing custom code, using robust and popular contrib modules you're
  21. left with only Rules and/or Context. For the sake of triggering redirects
  22. both modules will work almost identically under the hood so use whichever suits
  23. your current needs best.
  24. ## Caveats ##
  25. If your site is only using Drupal core caching, configured entirely through
  26. the Performance configuration screen you can skip this section.
  27. Context is fundamentally a PHP framework for checking existing conditions and
  28. reacting to them. It does this though Drupal's system of "hooks" that have
  29. always provided this functionality for developers writing their own code, but
  30. with a nice point-and-click interface to make it accessible to a wider audience.
  31. In this way Context is very similar to the Rules module.
  32. Because Context is built on hooks it is a flexible and powerful way to manage
  33. redirects. It allows the site builder to react to more subtle conditions
  34. than just a path. For example, a user visiting the home page with a specific
  35. role can be detected and redirected easily.
  36. Unfortunately, redirects triggered by hooks are in danger of being bypassed
  37. completely when Drupal and/or the server environment is configured so that hooks
  38. are not triggered if the current page is cached. This is not the default
  39. configuration of Drupal, you need very specific skills and knowledge to create
  40. this problem for yourself - you should know who you are :P.
  41. Redirects from this module will fail if ALL of the following conditions are met:
  42. - The condition that triggers the redirect will be met by some anonymous users
  43. but not other.
  44. - The current Drupal site has "fast cache" page caching or equivalent enabled.
  45. The most common ways of achieving this are:
  46. => Using the Boost module
  47. => Manually setting the 'page_cache_invoke_hooks' variable to FALSE in
  48. settings.php and enabling page caching
  49. => Installing a server based html cache like Varnish that can bypass Drupal
  50. completely.
  51. => Using "Aggressive" page caching in Drupal 6
  52. - The current page is cached
  53. - The cached version of this page is not a redirect, or redirects to the wrong
  54. url.
  55. A practical example that meets all of these conditions would be a site with
  56. Boost enabled that is attempting to redirect only those anonymous users that
  57. view the site with mobile devices.
  58. Generally though, if all of these conditions are met and you're expecting a PHP
  59. based redirect to work reliably you probably need to rethink your site
  60. architecture and use a server config or client (javascript) based redirection.