From ec27fd45868318542f365ec4ec1b3c9d5084f586 Mon Sep 17 00:00:00 2001
From: Romain Derie <rde@odoo.com>
Date: Mon, 24 Jul 2023 14:14:16 +0000
Subject: [PATCH] [FIX] website: allow again external website redirect

Broken by commit [1], where only the `url_to` should've been part of the
check for 301/302. The rest of the `if` was about relative URL check,
routing map check and converter check, all related to 308 only.

Note that in the meantime, commit [2] was added in those checks and
needs to be part of 301/302 too.

[1]: https://github.com/odoo/odoo/commit/14a850976711431f36b7f889ea9cf31b1114513d
[2]: https://github.com/odoo/odoo/commit/26fa923f6ab01298bf1a1e9f6a615c9aa9e2e5ed

Fixes https://github.com/odoo/odoo/issues/129290

closes odoo/odoo#129410

Signed-off-by: Benoit Socias (bso) <bso@odoo.com>
---
 addons/website/models/website_rewrite.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/addons/website/models/website_rewrite.py b/addons/website/models/website_rewrite.py
index ba03e4cf5c9f..5eea438b8959 100644
--- a/addons/website/models/website_rewrite.py
+++ b/addons/website/models/website_rewrite.py
@@ -85,10 +85,12 @@ class WebsiteRewrite(models.Model):
             if rewrite.redirect_type in ['301', '302', '308']:
                 if not rewrite.url_to:
                     raise ValidationError(_('"URL to" can not be empty.'))
-                elif not rewrite.url_to.startswith('/'):
-                    raise ValidationError(_('"URL to" must start with a leading slash.'))
                 if not rewrite.url_from:
                     raise ValidationError(_('"URL from" can not be empty.'))
+
+            if rewrite.redirect_type == '308':
+                if not rewrite.url_to.startswith('/'):
+                    raise ValidationError(_('"URL to" must start with a leading slash.'))
                 for param in re.findall('/<.*?>', rewrite.url_from):
                     if param not in rewrite.url_to:
                         raise ValidationError(_('"URL to" must contain parameter %s used in "URL from".') % param)
-- 
GitLab