In Drupal 7, you can redirect users from one page to another using various methods. Here are three common methods to implement redirects in Drupal 7:
1. Using the drupal_goto() Function:
– The `drupal_goto()` function is a Drupal core function that can be used to redirect users programmatically.
– The function takes the destination URL and optional parameters as arguments.
– Place the `drupal_goto()` function in your custom module or theme files to perform the redirect.
– Example usage:
“`php
<?php
// Redirect to a specific path.
drupal_goto(‘path/to/redirect’);
// Redirect to an external URL.
drupal_goto(‘http://www.example.com’);
// Redirect with additional options.
drupal_goto(‘path/to/redirect’, array(‘query’ => array(‘key’ => ‘value’), ‘fragment’ => ‘section’));
?>
“`
2. Using the Rules module:
– The Rules module allows you to create custom site actions and reactions, including redirects.
– Install and enable the Rules module (https://www.drupal.org/project/rules).
– Create a new rule:
– Configure the event that triggers the redirect (e.g., “Content is viewed,” “User logs in,” etc.).
– Add an action to redirect to a specific URL or path.
– Save the rule and test the redirect.
3. Using the Redirect module:
– The Redirect module provides a user interface to manage URL redirects within Drupal.
– Install and enable the Redirect module (https://www.drupal.org/project/redirect).
– Navigate to Configuration > Search and metadata > URL redirects.
– Add a new redirect by specifying the source path and the destination URL.
– Save the redirect, and Drupal will automatically redirect users from the source path to the destination URL.
These methods should cover most use cases for implementing redirects in Drupal 7. Choose the method that suits your requirements and the level of control you need over the redirects. Remember to always test the redirects to ensure they are functioning as expected and to handle any potential conflicts with other modules or custom code on your site.