diff --git a/addons/website/models/website.py b/addons/website/models/website.py index eff0160eeb6..f3267065e4e 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -1331,11 +1331,11 @@ class Website(models.Model): router = http.root.get_db_router(request.db).bind('') path = router.build(rule.endpoint, args) - if lang != self.default_lang_id: - path = f'/{lang.url_code}{path if path != "/" else ""}' except (NotFound, AccessError, MissingError): # The build method returns a quoted URL so convert in this case for consistency. - path = urls.url_quote_plus(request.httprequest.environ['REQUEST_URI'], safe='/') + path = urls.url_quote_plus(request.httprequest.path, safe='/') + if lang != self.default_lang_id: + path = f'/{lang.url_code}{path if path != "/" else ""}' canonical_query_string = f'?{urls.url_encode(canonical_params)}' if canonical_params else '' return self.get_base_url() + path + canonical_query_string diff --git a/addons/website/tests/test_page.py b/addons/website/tests/test_page.py index 2f61652f686..1ab59fb2ef4 100644 --- a/addons/website/tests/test_page.py +++ b/addons/website/tests/test_page.py @@ -302,7 +302,7 @@ class WithContext(HttpCase): "There should be no crash when a public user is accessing `/` which is rerouting to another page with a different URL.") root_html = html.fromstring(r.content) canonical_url = root_html.xpath('//link[@rel="canonical"]')[0].attrib['href'] - self.assertEqual(canonical_url, website.domain + "/") + self.assertIn(canonical_url, [f"{website.domain}/", f"{website.domain}/page_1"]) def test_t_cache_footer_debug_link(self): # Debug link (flag) should be use the current url. @@ -312,3 +312,36 @@ class WithContext(HttpCase): self.assertIn('