diff --git a/redirect.module b/redirect.module index 6e8d9b2..6afdd47 100644 --- a/redirect.module +++ b/redirect.module @@ -206,19 +206,30 @@ function redirect_menu() { * Implements hook_url_inbound_alter(). */ function redirect_url_inbound_alter(&$path, $original_path, $path_language) { - // Redirect to canonical URLs. - if ($path && variable_get('redirect_canonical', 1)) { - $alias = drupal_get_path_alias($path, $path_language); - if ($alias != $path && $alias != $original_path) { - //return redirect_redirect(array('redirect' => $alias, 'type' => 'global')); - } + // Check for empty path or disabled canonical redirects. + if (empty($path) || !variable_get('redirect_canonical', 1)) { + return; + } + // Do not redirect from cron.php or anywhere else but index.php. + $script_path = $_SERVER['SCRIPT_NAME'] ? $_SERVER['SCRIPT_NAME'] : $_SERVER['SCRIPT_FILENAME']; + if ($script_path !== $GLOBALS['base_path'] . 'index.php') { + return; + } + // Do not redirect */search/redirect or */search/path pages. + if (arg(2) === 'search' && (arg(3) === 'redirect' || arg(3) === 'path')) { + return; + } + $alias = drupal_get_path_alias($path, $path_language); - // Redirect from default entity paths to the proper entity path. - if ($path_entity = redirect_load_entity_from_path($path)) { - $uri = entity_uri($path_entity['entity_type'], $path_entity['entity']); - if ($path != $uri['path']) { - //return redirect_redirect(array('redirect' => $uri['path'], 'redirect_options' => $uri['options'], 'type' => 'global')); - } + if ($alias != $path && $alias != $original_path) { + return redirect_redirect(array('redirect' => $alias, 'type' => 'global')); + } + + // Redirect from default entity paths to the proper entity path. + if ($path_entity = redirect_load_entity_from_path($path)) { + $uri = entity_uri($path_entity['entity_type'], $path_entity['entity']); + if ($path != $uri['path']) { + return redirect_redirect(array('redirect' => $uri['path'], 'redirect_options' => $uri['options'], 'type' => 'global')); } } } @@ -260,20 +271,20 @@ function redirect_init() { // 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); + $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); + $redirect_global = TRUE; + $request_uri = str_replace('index.php', '', $request_uri); } - //$request_uri = ltrim($request_uri, '/'); - //$parsed = parse_url($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')); + redirect_redirect(array('redirect' => $request_uri, 'type' => 'global')); } }