diff --git a/includes/locale.inc b/includes/locale.inc
index c7f9583..45f409a 100644
--- a/includes/locale.inc
+++ b/includes/locale.inc
@@ -448,7 +448,9 @@ function locale_language_url_rewrite_url(&$path, &$options) {
           $host = parse_url($host, PHP_URL_HOST);
 
           // Apply the appropriate protocol to the URL.
-          $options['base_url'] = $url_scheme . $host;
+          global $base_path;
+          $trimmed_base_path = rtrim($base_path, '/');
+          $options['base_url'] = $url_scheme . $host . $trimmed_base_path;
           if (isset($options['https']) && variable_get('https', FALSE)) {
             if ($options['https'] === TRUE) {
               $options['base_url'] = str_replace('http://', 'https://', $options['base_url']);
diff --git a/modules/locale/locale.test b/modules/locale/locale.test
index 9086587..b732e0e 100644
--- a/modules/locale/locale.test
+++ b/modules/locale/locale.test
@@ -2512,6 +2512,9 @@ class LocaleUILanguageNegotiationTest extends DrupalWebTestCase {
     global $is_https;
     $languages = language_list();
 
+    global $base_path;
+    $trimmed_base_path = rtrim($base_path, '/');
+
     foreach (array('it', 'fr') as $langcode) {
       // Build the link we're going to test based on the clean URL setting.
       $link = (!empty($GLOBALS['conf']['clean_url'])) ? $langcode . '.example.com/admin' : $langcode . '.example.com/?q=admin';
@@ -2521,13 +2524,13 @@ class LocaleUILanguageNegotiationTest extends DrupalWebTestCase {
       // @see UrlAlterFunctionalTest::assertUrlOutboundAlter (path.test).
       $url = url('admin', array('language' => $languages[$langcode]));
       $url_scheme = ($is_https) ? 'https://' : 'http://';
-      $correct_link = $url_scheme . $link;
+      $correct_link = $url_scheme . $link . $trimmed_base_path;
       $this->assertTrue($url == $correct_link, format_string('The url() function returns the right url (@url) in accordance with the chosen language', array('@url' => $url . " == " . $correct_link)));
 
       // Test HTTPS via options.
       variable_set('https', TRUE);
       $url = url('admin', array('https' => TRUE, 'language' => $languages[$langcode]));
-      $correct_link = 'https://' . $link;
+      $correct_link = 'https://' . $link . $trimmed_base_path;
       $this->assertTrue($url == $correct_link, format_string('The url() function returns the right https url (via options) (@url) in accordance with the chosen language', array('@url' => $url . " == " . $correct_link)));
       variable_set('https', FALSE);
 
@@ -2535,7 +2538,7 @@ class LocaleUILanguageNegotiationTest extends DrupalWebTestCase {
       $temp_https = $is_https;
       $is_https = TRUE;
       $url = url('admin', array('language' => $languages[$langcode]));
-      $correct_link = 'https://' . $link;
+      $correct_link = 'https://' . $link . $trimmed_base_path;
       $this->assertTrue($url == $correct_link, format_string('The url() function returns the right url (via current url scheme) (@url) in accordance with the chosen language', array('@url' => $url . " == " . $correct_link)));
       $is_https = $temp_https;
     }
diff --git a/modules/simpletest/tests/upgrade/upgrade.locale.test b/modules/simpletest/tests/upgrade/upgrade.locale.test
index 2a3056b..7b09eb9 100644
--- a/modules/simpletest/tests/upgrade/upgrade.locale.test
+++ b/modules/simpletest/tests/upgrade/upgrade.locale.test
@@ -106,8 +106,10 @@ class LocaleUpgradePathTestCase extends UpgradePathTestCase {
     // The language switcher block should point to http://en.example.com.
     $language_links = $this->xpath('//ul[contains(@class, :class)]/li/a', array(':class' => 'language-switcher-locale-url'));
     $found_english_link = FALSE;
+    global $base_path;
+    $trimmed_base_path = rtrim($base_path, '/');
     foreach ($language_links as $link) {
-      if ((string) $link['href'] == 'http://en.example.com/') {
+      if ((string) $link['href'] == 'http://en.example.com' . $trimmed_base_path) {
         $found_english_link = TRUE;
       }
     }
