Index: uc_cart/uc_cart.module
===================================================================
--- uc_cart/uc_cart.module	(revision 1015)
+++ uc_cart/uc_cart.module	(working copy)
@@ -324,18 +324,41 @@
 function uc_cart_form_alter(&$form, $form_state, $form_id) {
   // Redirect shopper back to checkout page if they go to login from there.
   if ($form_id == 'user_login' || $form_id == 'user_edit' || $form_id == 'user_register') {
+    // Parse the existing #action url.
+    $p = parse_url($form['#action']);
+    $query = array();
+    if ($p['query']) {
+      parse_str($p['query'], $query);
+    }
+    if ($p['scheme']) {
+      // Path is an absolute URL.
+      $path = $p['scheme'] .'://'
+        . ($p['user'] ? $p['user'] . ($p['pass'] ? ':'. $p['pass'] : '') .'@' : '')
+        . ($p['host'] ? $p['host'] : '')
+        . ($p['path'] ? $p['path'] : '');
+    }
+    else {
+      // Path needs to be an internal path so we can pass it to url() later.
+      // Strip off the base path.
+      $path = substr($p['path'], drupal_strlen(base_path()));
+    }
+
+    // Figure out the destination.
     if ($_SESSION['checkout-redirect'] == TRUE) {
-      $form['#action'] = url($_GET['q'], array('query' => 'destination=cart/checkout'));
+      $query['destination'] = 'cart/checkout';
     }
     else {
       // Compare the referer to checkout page URLs.
       if (uc_referer_check('cart/checkout') && uc_referer_uri() != '') {
-        $form['#action'] = url($_GET['q'], array('query' => 'destination=cart/checkout'));
+        $query['destination'] = 'cart/checkout';
       }
       elseif (uc_referer_check(array('cart/checkout/review', 'cart/checkout/complete')) && uc_referer_uri() != '') {
-        $form['#action'] = url($_GET['q'], array('query' => 'destination=user'));
+        $query['destination'] = 'user';
       }
     }
+
+    // Build the new #action url.
+    $form['#action'] = url($path, array('query' => $query, 'fragment' => $p['fragment']));
   }
 
   if ($form_id == 'user_login' || $form_id == 'user_login_block') {
