[FIX] website: fix / optimize canonical url
Homepage was never considered as canonical due to the trailing / domain.com/fr/ != domain.com/fr Now _get_canonical_url_localized for homepage is fixed. Remove all computation related to canonical that is usless for connected user. It is mainly used for SEO tools/bots/crawler. Initially planed for 13.0 with [1] but reverted with [2]. [1]: https://github.com/odoo/odoo/commit/33167b3928c767a08fdc7eedc3e6204aac9cac08 [2]: https://github.com/odoo/odoo/commit/deb23450f18196c7f8d9e819db603fccd407b82a closes odoo/odoo#94289 X-original-commit: 375abe5e369b59a57b352d68d4835f2ef275b560 Signed-off-by: Romain Derie (rde) <rde@odoo.com> Signed-off-by: Jérémy Kersten <jke@odoo.com>
This commit is contained in:
@@ -1327,7 +1327,7 @@ 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}'
|
||||
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='/')
|
||||
|
||||
@@ -85,7 +85,7 @@ class TestBaseUrl(TestUrlCommon):
|
||||
self._assertCanonical('/?debug=1', self.website.get_base_url() + '/')
|
||||
self._assertCanonical('/a-page', self.website.get_base_url() + '/a-page')
|
||||
self._assertCanonical('/en_US', self.website.get_base_url() + '/')
|
||||
self._assertCanonical('/fr_FR', self.website.get_base_url() + '/fr/')
|
||||
self._assertCanonical('/fr_FR', self.website.get_base_url() + '/fr')
|
||||
|
||||
|
||||
@odoo.tests.tagged('-at_install', 'post_install')
|
||||
|
||||
@@ -24,7 +24,7 @@ class TestLangUrl(HttpCase):
|
||||
|
||||
def test_01_url_lang(self):
|
||||
with MockRequest(self.env, website=self.website):
|
||||
self.assertEqual(url_lang('', '[lang]'), '/[lang]/mockrequest/', "`[lang]` is used to be replaced in the url_return after installing a language, it should not be replaced or removed.")
|
||||
self.assertEqual(url_lang('', '[lang]'), '/[lang]/mockrequest', "`[lang]` is used to be replaced in the url_return after installing a language, it should not be replaced or removed.")
|
||||
|
||||
def test_02_url_redirect(self):
|
||||
url = '/fr_WHATEVER/contactus'
|
||||
|
||||
@@ -14,7 +14,7 @@ from odoo.tools.misc import DotDict, frozendict
|
||||
|
||||
@contextlib.contextmanager
|
||||
def MockRequest(
|
||||
env, *, path='/mockrequest/', routing=True, multilang=True,
|
||||
env, *, path='/mockrequest', routing=True, multilang=True,
|
||||
context=frozendict(), cookies=frozendict(), country_code=None,
|
||||
website=None, remote_addr=HOST, environ_base=None,
|
||||
# website_sale
|
||||
|
||||
@@ -106,18 +106,18 @@
|
||||
<t t-foreach="twitter_meta" t-as="t_meta">
|
||||
<meta t-att-name="t_meta" t-att-content="twitter_meta[t_meta]"/>
|
||||
</t>
|
||||
|
||||
<t t-if="request and request.is_frontend_multilang and website">
|
||||
<t t-cache="website,canonical_params">
|
||||
<t t-set="alternate_languages" t-value="website._get_alternate_languages(canonical_params=canonical_params)"/>
|
||||
<t t-foreach="alternate_languages" t-as="lg">
|
||||
<link rel="alternate" t-att-hreflang="lg['hreflang']" t-att-href="lg['href']"/>
|
||||
</t>
|
||||
</t>
|
||||
</t>
|
||||
</t>
|
||||
<!-- `alternate`/`canonical` mainly useful to crawlers/bots/SEO tools, which test the website as public user -->
|
||||
<t t-if="request and request.is_frontend_multilang and website and website.is_public_user()">
|
||||
<t t-cache="website,canonical_params">
|
||||
<t t-set="alternate_languages" t-value="website._get_alternate_languages(canonical_params=canonical_params)"/>
|
||||
<t t-foreach="alternate_languages" t-as="lg">
|
||||
<link rel="alternate" t-att-hreflang="lg['hreflang']" t-att-href="lg['href']"/>
|
||||
</t>
|
||||
</t>
|
||||
</t>
|
||||
<link t-if="request and website" rel="canonical" t-att-href="website._get_canonical_url(canonical_params=canonical_params)"/>
|
||||
<link t-if="request and website and website.is_public_user()" rel="canonical" t-att-href="website._get_canonical_url(canonical_params=canonical_params)"/>
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin=""/>
|
||||
</xpath>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user