--- globalredirect.module.orig	2008-08-04 16:40:16.000000000 +0200
+++ globalredirect.module	2008-09-03 20:31:18.000000000 +0200
@@ -62,10 +62,19 @@ function globalredirect_init() {
       $query_string = NULL;
     }
 
+    // Establish the language prefix that should be used, ie. the one that drupal_goto() would use
+    $options = array('prefix' => '');
+    if (function_exists('language_url_rewrite')) {
+      // Note that language_url_rewrite() takes path (by reference) as the first argument but does not use it at all
+      $path = $_REQUEST['q'];
+      language_url_rewrite($path, $options); 
+    }
+    $prefix = rtrim($options['prefix'], '/');
+
     // Do a check if this is a frontpage
     if (drupal_is_front_page()) {
-      // If the current reques is NOT the language prefix (eg, /de/node) then redirect to the prefix
-      if ($_REQUEST['q'] != $language->prefix) {
+      // Redirect if the current request does not refer to the frontpage in the configured fashion (with or without a prefix)
+      if ($_REQUEST['q'] != $prefix) {
         drupal_goto('', $query_string, NULL, 301);
       }
       // If we've got to this point then we're on a frontpage with a VALID request path (such as a language-prefix frontpage such as '/de')
@@ -75,11 +84,14 @@ function globalredirect_init() {
     // Trim any trailing slash off the end (eg, 'node/1/' to 'node/1')
     $request = trim($_GET['q'], '/');
 
-    // Check the path (eg, node/123) for the request
+    // Find an alias (if any) for the request. If we have a language prefix then prefix the alias
     $alias = drupal_get_path_alias($request);
+    if ($prefix) {
+      $alias = empty($alias) ? $prefix : $prefix . '/' . $alias;
+    }
 
-    // Compare the request to the alias. If we have a language prefix then prefix the alias and compare. This also works as a 'deslashing' agent too
-    if ((empty($language->prefix) ? $alias : $language->prefix .'/'. $alias) != $_REQUEST['q']) {
+    // Compare the request to the alias. This also works as a 'deslashing' agent
+    if ($_REQUEST['q'] != $alias) {
       drupal_goto($alias, $query_string, NULL, 301);
     }
 
