diff --git a/includes/common.inc b/includes/common.inc
index de31897..061cbed 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -1066,7 +1066,17 @@ function drupal_http_request($url, array $options = array()) {
     case 301: // Moved permanently
     case 302: // Moved temporarily
     case 307: // Moved temporarily
-      $location = $result->headers['location'];
+      $location = parse_url($result->headers['Location']);
+      // If location isn't fully qualified URL (as per W3 RFC2616), build one
+      if (!isset($location['scheme']) && !isset($location['host'])) {
+        $check_scheme = isset($uri['scheme']) ? $uri['scheme'] : '';
+        $check_host = isset($uri['host']) ? $uri['host'] : '';
+        $check_port = isset($uri['port']) ? ':' . $uri['port'] : '';
+        $location = $check_scheme . '://' . $check_host . $check_port . '/' . ltrim($result->headers['Location'], '/');
+      }
+      else {
+        $location = $result->headers['Location'];
+      }
       $options['timeout'] -= timer_read(__FUNCTION__) / 1000;
       if ($options['timeout'] <= 0) {
         $result->code = HTTP_REQUEST_TIMEOUT;
