From e6997dae2bc4e1c4fbc2de3a8e6fa33967db5b33 Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Fri, 14 Feb 2020 17:23:17 +0000 Subject: [PATCH] [FIX] website_blog: avoid loop of redirect if no trailing / in tag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- addons/website_blog/controllers/main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/website_blog/controllers/main.py b/addons/website_blog/controllers/main.py index 737731b88a4..ee6b17ba303 100644 --- a/addons/website_blog/controllers/main.py +++ b/addons/website_blog/controllers/main.py @@ -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'):