You are here

function redirect_redirect in Redirect 7

Same name and namespace in other branches
  1. 7.2 redirect.module \redirect_redirect()

Perform an URL redirect.

Parameters

$redirect: An optional URL redirect array.

Related topics

1 call to redirect_redirect()
redirect_init in ./redirect.module
Implements hook_init().
1 string reference to 'redirect_redirect'
redirect_element_validate_source in ./redirect.admin.inc
Element validate handler; validate the source of an URL redirect.

File

./redirect.module, line 1124

Code

function redirect_redirect($redirect = NULL) {
  if (!isset($redirect)) {
    $redirect = new stdClass();
  }
  redirect_object_prepare($redirect, array(
    'redirect' => current_path(),
    'type' => 'manual',
    'callback' => 'redirect_goto',
    'cache' => TRUE,
  ));

  // Rewrite redirect URLs to absolute file URIs.
  if ($scheme = file_uri_scheme($redirect->redirect)) {
    if (file_stream_wrapper_valid_scheme($scheme)) {
      if ($external_path = file_create_url($redirect->redirect)) {
        $redirect->redirect = $external_path;
      }
    }
  }
  if (empty($redirect->status_code)) {
    $redirect->status_code = variable_get('redirect_default_status_code', 301);
  }

  // Get global passthrough configuration by default.
  $passthrough_querystring = variable_get('redirect_passthrough_querystring', 1);

  // Individual redirects can be configured to override the global configuration.
  if (isset($redirect->redirect_options['passthrough_querystring'])) {
    $passthrough_querystring = $redirect->redirect_options['passthrough_querystring'];
  }
  if ($passthrough_querystring) {

    // Preserve the current query parameters in the redirect.
    $redirect->redirect_options += array(
      'query' => array(),
    );
    $redirect->redirect_options['query'] += drupal_get_query_parameters();
  }

  // Prevent the destination query parameter from overriding this redirect.

  //if (isset($_GET['destination'])) {

  // Simply unset the parameter since it has already been passed into
  // $options['query'] in the previous code.
  //  unset($_GET['destination']);

  //}

  // Allow other modules to alter the redirect before passing to drupal_goto().
  drupal_alter('redirect', $redirect);

  // Continue if the redirect has not been disabled by hook_redirect_alter().
  if (isset($redirect->redirect) && isset($redirect->callback) && $redirect->redirect !== FALSE && function_exists($redirect->callback)) {

    // Prevent circular redirects.
    if ($GLOBALS['base_root'] . request_uri() == url($redirect->redirect, array(
      'absolute' => TRUE,
    ) + $redirect->redirect_options)) {
      return FALSE;
    }

    // Perform the actual redirect.
    $callback = $redirect->callback;
    $callback($redirect);
  }
}