diff --git a/core/modules/language/lib/Drupal/language/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php b/core/modules/language/lib/Drupal/language/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php
index a72ca44..eacb5c4 100644
--- a/core/modules/language/lib/Drupal/language/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php
+++ b/core/modules/language/lib/Drupal/language/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php
@@ -162,7 +162,7 @@ public function processOutbound($path, &$options = array(), Request $request = N
           list(, $port) = explode(':', $normalized_base_url);
           $options['base_url'] .= ':' . $port;
         }
-        elseif ($port != 80) {
+        elseif (($url_scheme == 'http' && $port != 80) || ($url_scheme == 'https' && $port != 443)) {
           $options['base_url'] .= ':' . $port;
         }
 
diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php
index 847348e..09cb363 100644
--- a/core/modules/language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php
+++ b/core/modules/language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php
@@ -124,7 +124,9 @@ function testDomainNameNegotiationPort() {
     // URLs as well.
     $index_php = strpos(url('', array('absolute' => TRUE)), 'index.php') !== FALSE;
 
-    $request = $this->prepareRequestForGenerator(TRUE, array('SERVER_PORT' => '88'));
+    $request = Request::createFromGlobals();
+    $server = $request->server->all();
+    $request = $this->prepareRequestForGenerator(TRUE, array('HTTP_HOST' => $server['HTTP_HOST'] . ':88'));
 
     // Create an absolute French link.
     $language = language_load('fr');
