Index: globalredirect.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/globalredirect/globalredirect.module,v
retrieving revision 1.1.2.4.2.2
diff -u -w -F^f -r1.1.2.4.2.2 globalredirect.module
--- globalredirect.module	6 Feb 2007 01:09:28 -0000	1.1.2.4.2.2
+++ globalredirect.module	16 Apr 2007 21:58:01 -0000
@@ -20,34 +20,26 @@ function globalredirect_init() {
   if(isset($_REQUEST['q']) && function_exists('drupal_get_path_alias') && !isset($_REQUEST['destination'])) {
     
     //Get the Query String (minus the 'q'). If none set, set to NULL
-    if (($query_string = drupal_query_string_encode($_GET, array('q'))) == '') {
+    $query_string = drupal_query_string_encode($_GET, array('q'));
+    if (empty($query_string)) {
       $query_string = NULL;
     }
 
-
-
-    //Lets do a check to compare the current url to the site's frontpage.
-    //  If matches, redirect to the frontpage (eg, http://www.mysite.com/)
+    // If current path is also the frontpage, redirect to http://www.mysite.com.
     if(drupal_is_front_page()) {
       drupal_goto('', $query_string, NULL, 301);
     }
 
+    // Get the request string (minus trailing slash e.g. node/123/)
+    $request = preg_replace('/\/$/', '', $_REQUEST['q']);
     
-    
-    //Check the current url (eg, node/123) for an alias... If set, redirect to it
-    $alias = drupal_get_path_alias($_REQUEST['q']);
-    if ($alias != $_REQUEST['q']) {
+    //Check the path (eg, node/123) for an alias. If one is found, redirect.
+    if ($alias = drupal_get_path_alias($request)) {
+      if ($alias != $request) {
       drupal_goto($alias, $query_string, NULL, 301);
     }
-    
-    
-    //Check if the current url ends in a slash (eg, node/123/)
-    if(substr($_REQUEST['q'], -1) == "/") {
-      //Ok - it does. Seeing as it didn't have an exact match WITH the slash in the above test, lets try without...
-      $alias = drupal_get_path_alias(substr($_REQUEST['q'], 0, -1));
-      if ($alias != $_REQUEST['q']) {
-        //We matched an alias for the current URL with no slash - redirect to that...
-        drupal_goto($alias, $query_string, NULL, 301);
+      if ($request != $_REQUEST['q']) {
+        drupal_goto($request, $query_string, NULL, 301);
       }
     }
   }
