[FIX] website_blog: avoid loop of redirect if no trailing / in tag

Before this commit in case you start on blog with url like /blog/blog-1/tag/2,
you should be redirected to /blog/blog-1/tag/website-2 to avoid duplicate
content.

But because the replace was done with /tag/%s/ it will be not replaced and so
you are redirected to the same url, creating a loop.

closes odoo/odoo#45927

X-original-commit: 666306326cecc6ac8587b45d2dbf24c0463b33a5
Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
This commit is contained in:
Jeremy Kersten
2020-02-21 12:30:15 +00:00
parent 01028b1cf3
commit e6997dae2b
+3 -2
View File
@@ -71,8 +71,9 @@ class WebsiteBlog(http.Controller):
if active_tag_ids:
fixed_tag_slug = ",".join(slug(t) for t in request.env['blog.tag'].browse(active_tag_ids).exists())
if fixed_tag_slug != tags:
return request.redirect(request.httprequest.full_path.replace("/tag/%s/" % tags, "/tag/%s/" % fixed_tag_slug, 1), 301)
new_url = request.httprequest.full_path.replace("/tag/%s" % tags, "/tag/%s" % fixed_tag_slug, 1)
if new_url != request.httprequest.full_path: # check that really replaced and avoid loop
return request.redirect(new_url, 301)
domain += [('tag_ids', 'in', active_tag_ids)]
if request.env.user.has_group('website.group_website_designer'):