diff --git a/django/middleware/locale.py b/django/middleware/locale.py index 77113e29879..628782b1815 100644 --- a/django/middleware/locale.py +++ b/django/middleware/locale.py @@ -33,9 +33,12 @@ class LocaleMiddleware(object): language_path = '/%s%s' % (language, request.path_info) if settings.APPEND_SLASH and not language_path.endswith('/'): language_path = language_path + '/' + if is_valid_path(language_path, urlconf): - return HttpResponseRedirect( - '/%s%s' % (language, request.get_full_path())) + language_url = "%s://%s/%s%s" % ( + request.is_secure() and 'https' or 'http', + request.get_host(), language, request.get_full_path()) + return HttpResponseRedirect(language_url) translation.deactivate() patch_vary_headers(response, ('Accept-Language',)) diff --git a/tests/regressiontests/i18n/patterns/tests.py b/tests/regressiontests/i18n/patterns/tests.py index 1216d0bde99..16fbec014a9 100644 --- a/tests/regressiontests/i18n/patterns/tests.py +++ b/tests/regressiontests/i18n/patterns/tests.py @@ -182,12 +182,10 @@ class URLRedirectWithoutTrailingSlashTests(URLTestCaseBase): self.assertRedirects(response, '/not-prefixed/', 301) def test_en_redirect(self): - response = self.client.get('/account/register', HTTP_ACCEPT_LANGUAGE='en') + response = self.client.get('/account/register', HTTP_ACCEPT_LANGUAGE='en', follow=True) # target status code of 301 because of CommonMiddleware redirecting - self.assertRedirects(response, '/en/account/register', 302, target_status_code=301) - - response = self.client.get(response['location']) - self.assertRedirects(response, '/en/account/register/', 301) + self.assertIn(('http://testserver/en/account/register/', 301), response.redirect_chain) + self.assertRedirects(response, '/en/account/register/', 302) class URLRedirectWithoutTrailingSlashSettingTests(URLTestCaseBase):