Index: globalredirect.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/globalredirect/globalredirect.module,v retrieving revision 1.1.2.4.2.7 diff -u -p -r1.1.2.4.2.7 globalredirect.module --- globalredirect.module 29 Dec 2007 15:19:53 -0000 1.1.2.4.2.7 +++ globalredirect.module 15 Apr 2008 23:22:44 -0000 @@ -24,21 +24,58 @@ function globalredirect_init() { $query_string = NULL; } + // Trim any trailing slash off the end (eg, 'node/1/' to 'node/1') or for locales (eg, 'en/' should be just 'en') + $request = trim($_REQUEST['q'], '/'); + // 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); + if (!empty($request) && drupal_is_front_page()) { + //If i18n is enabled... + if (module_exists('i18n')) { + /// ...then we need to check if the frontpage is the default language + $lang = i18n_get_lang(); + if ($lang == i18n_default_language()) { + // If the current page language IS the default language, then redirect to root. + // This includes 'en' and 'en/node' to '' if 'en' is the default language (for example) + drupal_goto('', $query_string, NULL, 301); + } + elseif ($lang != $request) { + // If the current page doesn't equal the currently language BUT IS STILL a frontpage then redirect to frontpage. + // This includes 'fr/node'/ to 'fr' (for example) + drupal_goto($lang, $query_string, NULL, 301); + } + } + else { + 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. + // Check the current request for an alias $alias = drupal_get_path_alias($request); // If alias is different to the request, redirect... if ($alias != $request) { drupal_goto($alias, $query_string, NULL, 301); } + + //Handle i18n paths differently to 'normal' paths - requires extra work! + if(module_exists('i18n')) { + //Get the 'normal' path of the request (eg, 'en/node/1' to 'node/1') + $path = i18n_get_normal_path($request); + + //Get the alias for the i18n version of the request + $i18n_alias = drupal_get_path_alias($path); + + //If the i18n alias differs to the request then redirect + if ($i18n_alias != $request) { + if (i18n_get_lang_prefix($request) != i18n_get_lang()) { + $i18n_alias = i18n_path($path,i18n_get_lang_prefix($request)); + } + + //If the prefix checks didn't redirec then send the user to the path alias + drupal_goto($i18n_alias, $query_string, NULL, 301); + } + } + // If the trimmed request differs to the request then redirect (basically, de-slash the source path) if ($request != $_REQUEST['q']) {