diff --git a/includes/locale.inc b/includes/locale.inc
index 7fb8d64..0713a83 100644
--- a/includes/locale.inc
+++ b/includes/locale.inc
@@ -279,6 +279,11 @@ function locale_language_from_url($languages) {
       break;
 
     case LOCALE_LANGUAGE_NEGOTIATION_URL_DOMAIN:
+      // Get only the host, not the port.
+      $http_host= $_SERVER['HTTP_HOST'];
+      if (strpos($http_host, ':') !== FALSE) {
+        $http_host = current(explode(':', $http_host));
+      }
       foreach ($languages as $language) {
         // Skip check if the language doesn't have a domain.
         if ($language->domain) {
@@ -286,7 +291,7 @@ function locale_language_from_url($languages) {
           // Remove protocol and add http:// so parse_url works
           $host = 'http://' . str_replace(array('http://', 'https://'), '', $language->domain);
           $host = parse_url($host, PHP_URL_HOST);
-          if ($_SERVER['HTTP_HOST'] == $host) {
+          if ($http_host == $host) {
             $language_url = $language->language;
             break;
           }
diff --git a/modules/locale/locale.test b/modules/locale/locale.test
index ffda6f5..afc951b 100644
--- a/modules/locale/locale.test
+++ b/modules/locale/locale.test
@@ -2378,7 +2378,7 @@ class LocaleUILanguageNegotiationTest extends DrupalWebTestCase {
       array(
         'language_negotiation' => array(LOCALE_LANGUAGE_NEGOTIATION_URL, LANGUAGE_NEGOTIATION_DEFAULT),
         'locale_language_negotiation_url_part' => LOCALE_LANGUAGE_NEGOTIATION_URL_DOMAIN,
-        'locale_test_domain' => $language_domain,
+        'locale_test_domain' => $language_domain . ':88',
         'path' => 'admin/config',
         'expect' => $language_string,
         'expected_provider' => LOCALE_LANGUAGE_NEGOTIATION_URL,
