I need to redirect users to an external website when they access the node view page at node/%node
of a node meeting some conditions.
What would the proper/best way to achieve this (using code) be?
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityI would use hook_node_view
.
Remember to check the view mode along with the conditions, so you don't redirect on pages where only the teaser is shown.
It should look something like this:
module_node_view($node, $view_mode, $langcode) {
if ($view_mode == 'full' && "Conditions") {
drupal_goto('http://example.com');
}
}
We created a content type using CCK Redirection and then external links could be treated like nodes. So you could use node access modules, the rules module, etc. It has worked quite well for us.