You are here

function redirect_init in Redirect 7

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

Implements hook_init().

File

./redirect.module, line 308

Code

function redirect_init() {
  if (!redirect_can_redirect()) {
    return;
  }

  // Fetch the current redirect.
  if ($redirect = redirect_get_current_redirect()) {
    redirect_redirect($redirect);
  }
  $redirect_global = FALSE;
  $request_uri = $original_uri = ltrim(request_uri(), '/');

  // Redirect from non-clean URLs to clean URLs.
  if (variable_get('redirect_global_clean', 1) && variable_get('clean_url', 0) && strpos($request_uri, '?q=') !== FALSE) {

    //$redirect_global = TRUE;

    //$request_uri = str_replace('?q=', '', $request_uri);
  }
  if (strpos($request_uri, 'index.php') !== FALSE) {

    //$redirect_global = TRUE;

    //$request_uri = str_replace('index.php', '', $request_uri);
  }

  //$request_uri = ltrim($request_uri, '/');

  //$parsed = parse_url($request_uri);
  if ($redirect_global && $request_uri != $original_uri) {
    redirect_redirect(array(
      /*'redirect' => $request_uri,*/
      'type' => 'global',
    ));
  }
}