5a6,8 > > PLEASE NOTE: This is a heavily modified version of the original Global Redirect module, intended to handle the needs of multi-language sites (i18n installed). It has been designed to duplicate the functionality of the original Global Redirect module when i18n is not installed, but that has not yet been tested by the author. This version was produced by netgenius - drupal(a)netgenius(d)co(d)uk > 13c16 < return t('This module will do a 301 redirect for all nodes which have an alias but are not using that alias.'); --- > return t('This module will do a 301 redirect for all nodes which have an alias but are not using that alias. In the case of multi-language sites, it also redirects requests without a language code to a corresponding url with a language code.'); 17d19 < 31,32c33 < * 3) If there is a request. There is no point checking the REAL frontpage for an alias. < * 4) If the $_POST is empty. The problem which arises here is if a form posts to an source path rather than the alias. GlobalRedirect sometimes interrupts the post and redirects to the alias instead. --- > * 3) If the $_POST is empty. The problem which arises here is if a form posts to an source path rather than the alias. GlobalRedirect sometimes interrupts the post and redirects to the alias instead. 33a35,36 > > // To do: Could we improve performance by caching the result? 35,61c38,49 < if (function_exists('drupal_get_path_alias') && < _menu_item_is_accessible(menu_get_active_item()) && < isset($_REQUEST['q']) && < empty($_POST)) { < < //Store the destination from the $_REQUEST as it breaks things if we leave it in - restore it at the end... < if (isset($_REQUEST['destination'])) { < $destination = $_REQUEST['destination']; < unset($_REQUEST['destination']); < } < < // Get the Query String (minus the 'q'). If none set, set to NULL < $query_string = drupal_query_string_encode($_GET, array('q')); < if (empty($query_string)) { < $query_string = NULL; < } < < // If current path is also the frontpage, redirect to http://www.example.com. < if (!empty($_REQUEST['q']) && drupal_is_front_page()) { < drupal_goto('', $query_string, NULL, 301); < } < < // Trim any trailing slash off the end (eg, 'node/1/' to 'node/1') < $request = trim($_REQUEST['q'], '/'); < < // Check the path (eg, node/123) for an request. < $alias = drupal_get_path_alias($request); --- > // Bail-out if the Path module is not initialised. > if (!is_callable('drupal_get_path_alias')) return false; > // Bail-out if requested path is not accessible to the user. > if (!_menu_item_is_accessible(menu_get_active_item())) return false; > // Bail-out if $_POST is not empty. > if (!empty($_POST)) return false; > > //Store the destination from the $_REQUEST as it breaks things if we leave it in - restore it at the end... > if (isset($_REQUEST['destination'])) { > $destination = $_REQUEST['destination']; > unset($_REQUEST['destination']); > } 63,66c51,78 < // If alias is different to the request, redirect... < if ($alias != $request) { < drupal_goto($alias, $query_string, NULL, 301); < } --- > // Get the Query String (minus the 'q'). If none, set to NULL > $query_string = drupal_query_string_encode($_GET, array('q')); > if (!$query_string) $query_string = NULL; > > // Get the request and trim any trailing slash (eg, 'node/1/' to 'node/1') > $request = $_REQUEST['q']; > $target = trim($request, '/'); > > // Get alias, or for the front-page just use empty path (a language code is added later, if applicable). > // Note: "non-friendly" urls get converted to "friendly" urls here too. > $alias = drupal_is_front_page()? '' : drupal_get_path_alias($target); > > // If i18n is installed, we need to handle language codes in requested and alias urls... > if (is_callable('i18n_url_rewrite')) { > // If no alias was found, get the alternative url (with/without language prefix) and try again... > if ($alias == $target) { > // Try to get the generic target (without language code). > $alt_target = i18n_url_rewrite('source', $target, ''); > // If it's the same then we already had the generic target, so get the language-specific target. > if ($alt_target == $target) $alt_target = i18n_url_rewrite('alias', $target, ''); > // Either way, try again to find an alias. > $alias = drupal_get_path_alias($alt_target); > } > // In all cases, make sure the final target url includes a language code... > // This means that Search Engines won't see a duplicate for site.com/path as site.com/en/path. > // However, it does not prevent site.com/aa/path being seen as a duplicate of site.com/bb/path if both produce the same content. > $alias = i18n_url_rewrite('alias', $alias, ''); > } 68,71c80,85 < // If the trimmed request differs to the request then redirect (basically, de-slash the source path) < if ($request != $_REQUEST['q']) { < drupal_goto($request, $query_string, NULL, 301); < } --- > // Restore the destination from earlier so its available in other places. > if (isset($destination)) $_REQUEST['destination'] = $destination; > > // Finally, do a redirect if the final url differs from the original request. > if ($alias != $request) drupal_goto($alias, $query_string, NULL, 301); > } 73,76c87 < //If no alias was returned, the final check is to direct non-clean to clean - if clean is enabled. < if ((bool)variable_get('clean_url', 0) && strpos(request_uri(), '?q=')) { < drupal_goto($request, $query_string, NULL, 301); < } --- > // -- End -- 78,81d88 < //Restore the destination from earlier so its available in other places. < if (isset($destination)) $_REQUEST['destination'] = $destination; < } < }