diff --git a/addons/http_routing/models/ir_http.py b/addons/http_routing/models/ir_http.py
index 3579a10f93b..444a8e5241f 100644
--- a/addons/http_routing/models/ir_http.py
+++ b/addons/http_routing/models/ir_http.py
@@ -369,14 +369,14 @@ class IrHttp(models.AbstractModel):
3/ Use the URL as-is saving the requested lang when the user is
a bot and that the lang is missing from the URL.
- 4/ Redirect the browser when the lang is missing from the URL
- but another lang than the default one has been requested. The
- requested lang is injected before the original path.
-
- 5) Use the url as-is when the lang is missing from the URL, that
+ 4) Use the url as-is when the lang is missing from the URL, that
another lang than the default one has been requested but that
it is forbidden to redirect (e.g. POST)
+ 5/ Redirect the browser when the lang is missing from the URL
+ but another lang than the default one has been requested. The
+ requested lang is injected before the original path.
+
6/ Redirect the browser when the lang is present in the URL but
it is the default lang. The lang is removed from the original
URL.
@@ -415,7 +415,11 @@ class IrHttp(models.AbstractModel):
else:
url_lang_str = ''
path_no_lang = path
- allow_redirect = request.httprequest.method != 'POST'
+
+ allow_redirect = (
+ request.httprequest.method != 'POST'
+ and getattr(request, 'is_frontend_multilang', True)
+ )
# There is no user on the environment yet but the following code
# requires one to set the lang on the request. Temporary grant
diff --git a/addons/test_website/tests/test_is_multilang.py b/addons/test_website/tests/test_is_multilang.py
index 22167234d01..38bf27c3338 100644
--- a/addons/test_website/tests/test_is_multilang.py
+++ b/addons/test_website/tests/test_is_multilang.py
@@ -57,6 +57,7 @@ class TestIsMultiLang(odoo.tests.HttpCase):
it_href = body.find('./head/link[@rel="alternate"][@hreflang="it"]').get('href')
fr_href = body.find('./head/link[@rel="alternate"][@hreflang="fr"]').get('href')
en_href = body.find('./head/link[@rel="alternate"][@hreflang="en"]').get('href')
+
self.assertEqual(urlparse(it_href).path, f'/{it.url_code}/test_lang_url/my-super-country-italia-{country1.id}')
self.assertEqual(urlparse(fr_href).path, f'/{be.url_code}/test_lang_url/my-super-country-belgium-{country1.id}')
self.assertEqual(urlparse(en_href).path, f'/test_lang_url/my-super-country-{country1.id}')
@@ -79,3 +80,18 @@ class TestIsMultiLang(odoo.tests.HttpCase):
self.assertRegex(r.text, r'')
r = self.url_open(be_prefix + '/contactus')
self.assertRegex(r.text, r'')
+
+ def test_04_multilang_false(self):
+ website = self.env['website'].search([], limit=1)
+ fr = self.env.ref('base.lang_fr').sudo()
+ en = self.env.ref('base.lang_en').sudo()
+ fr.active = True
+
+ website.default_lang_id = en
+ website.language_ids = en + fr
+ self.opener.cookies['frontend_lang'] = fr.iso_code
+
+ res = self.url_open('/get_post_nomultilang', allow_redirects=False)
+ res.raise_for_status()
+
+ self.assertEqual(res.status_code, 200, "Should not be redirected")