diff --git a/includes/locale.inc b/includes/locale.inc
index 780459b..4ab5239 100644
--- a/includes/locale.inc
+++ b/includes/locale.inc
@@ -207,8 +207,13 @@ function locale_language_from_url($languages) {
 
     case LOCALE_LANGUAGE_NEGOTIATION_URL_DOMAIN:
       foreach ($languages as $language) {
+        // Only compare the domains not the protocols or ports.
+        // Server HTTP_HOST should contain only the host, but double check
+        // Remove protocol and add http:// so parse_url works
+        $server_host = 'http://' . str_replace(array('http://', 'https://'), array('', ''), $_SERVER['HTTP_HOST']);
+        $server_host = parse_url($server_host, PHP_URL_HOST);
         $host = parse_url($language->domain, PHP_URL_HOST);
-        if ($host && ($_SERVER['HTTP_HOST'] == $host)) {
+        if ($host && ($server_host == $host)) {
           $language_url = $language->language;
           break;
         }
